From 40f5515e858223e913c00dca7cbbf9bd148ba122 Mon Sep 17 00:00:00 2001 From: longXboy Date: Thu, 23 May 2019 10:49:30 +0800 Subject: [PATCH] fix test --- pkg/net/rpc/warden/client.go | 2 ++ pkg/net/rpc/warden/resolver/direct/{ => test}/direct_test.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) rename pkg/net/rpc/warden/resolver/direct/{ => test}/direct_test.go (95%) diff --git a/pkg/net/rpc/warden/client.go b/pkg/net/rpc/warden/client.go index 5e892b459..b3681df68 100644 --- a/pkg/net/rpc/warden/client.go +++ b/pkg/net/rpc/warden/client.go @@ -156,6 +156,7 @@ func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error) { // NewClient returns a new blank Client instance with a default client interceptor. // opt can be used to add grpc dial options. func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client { + // Do not initialize in the registration, otherwise it may cause the resvoler in the business code to not register. resolver.Register(direct.New()) c := new(Client) if err := c.SetConfig(conf); err != nil { @@ -170,6 +171,7 @@ func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client { // DefaultClient returns a new default Client instance with a default client interceptor and default dialoption. // opt can be used to add grpc dial options. func DefaultClient() *Client { + // Do not initialize in the registration, otherwise it may cause the resvoler in the business code to not register. resolver.Register(direct.New()) _once.Do(func() { _defaultClient = NewClient(nil) diff --git a/pkg/net/rpc/warden/resolver/direct/direct_test.go b/pkg/net/rpc/warden/resolver/direct/test/direct_test.go similarity index 95% rename from pkg/net/rpc/warden/resolver/direct/direct_test.go rename to pkg/net/rpc/warden/resolver/direct/test/direct_test.go index 9399931c4..a3de922bf 100644 --- a/pkg/net/rpc/warden/resolver/direct/direct_test.go +++ b/pkg/net/rpc/warden/resolver/direct/test/direct_test.go @@ -11,6 +11,7 @@ import ( "github.com/bilibili/kratos/pkg/net/rpc/warden" pb "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/proto/testproto" "github.com/bilibili/kratos/pkg/net/rpc/warden/resolver" + "github.com/bilibili/kratos/pkg/net/rpc/warden/resolver/direct" xtime "github.com/bilibili/kratos/pkg/time" ) @@ -39,7 +40,7 @@ func createServer(name, listen string) *warden.Server { } func TestMain(m *testing.M) { - resolver.Register(New()) + resolver.Register(direct.New()) ctx := context.TODO() s1 := createServer("server1", "127.0.0.1:18081") s2 := createServer("server2", "127.0.0.1:18082")