From c6c0535ce6236f135e7a1fadc71539ce0d8c249f Mon Sep 17 00:00:00 2001 From: AlexStocks Date: Thu, 8 Oct 2020 21:06:19 +0800 Subject: [PATCH] Fix: ut fail --- protocol/dubbo/dubbo_invoker_test.go | 7 +++---- remoting/getty/pool.go | 15 +++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/protocol/dubbo/dubbo_invoker_test.go b/protocol/dubbo/dubbo_invoker_test.go index 4d32c29a22..c80f412ff0 100644 --- a/protocol/dubbo/dubbo_invoker_test.go +++ b/protocol/dubbo/dubbo_invoker_test.go @@ -89,15 +89,15 @@ func TestDubboInvokerInvoke(t *testing.T) { // destroy lock.Lock() + defer lock.Unlock() proto.Destroy() - lock.Unlock() } func InitTest(t *testing.T) (protocol.Protocol, common.URL) { hessian.RegisterPOJO(&User{}) - methods, err := common.ServiceMap.Register("", "dubbo", &UserProvider{}) + methods, err := common.ServiceMap.Register("com.ikurento.user.UserProvider", "dubbo", &UserProvider{}) assert.NoError(t, err) assert.Equal(t, "GetBigPkg,GetUser,GetUser0,GetUser1,GetUser2,GetUser3,GetUser4,GetUser5,GetUser6", methods) @@ -176,10 +176,9 @@ type ( // size:4801228 func (u *UserProvider) GetBigPkg(ctx context.Context, req []interface{}, rsp *User) error { argBuf := new(bytes.Buffer) - for i := 0; i < 400; i++ { + for i := 0; i < 800; i++ { // use chinese for test argBuf.WriteString("击鼓其镗,踊跃用兵。土国城漕,我独南行。从孙子仲,平陈与宋。不我以归,忧心有忡。爰居爰处?爰丧其马?于以求之?于林之下。死生契阔,与子成说。执子之手,与子偕老。于嗟阔兮,不我活兮。于嗟洵兮,不我信兮。") - argBuf.WriteString("击鼓其镗,踊跃用兵。土国城漕,我独南行。从孙子仲,平陈与宋。不我以归,忧心有忡。爰居爰处?爰丧其马?于以求之?于林之下。死生契阔,与子成说。执子之手,与子偕老。于嗟阔兮,不我活兮。于嗟洵兮,不我信兮。") } rsp.Id = argBuf.String() rsp.Name = argBuf.String() diff --git a/remoting/getty/pool.go b/remoting/getty/pool.go index 813aacba7f..8ceb673aa9 100644 --- a/remoting/getty/pool.go +++ b/remoting/getty/pool.go @@ -81,19 +81,26 @@ func newGettyRPCClientConn(pool *gettyRPCClientPool, addr string) (*gettyRPCClie gettyClient: gettyClient, } go c.gettyClient.RunEventLoop(c.newSession) + idx := 1 - times := int(pool.rpcClient.opts.ConnectTimeout / 1e6) + start := time.Now() + connectTimeout := pool.rpcClient.opts.ConnectTimeout for { idx++ if c.isAvailable() { break } - if idx > times { + if time.Now().Sub(start) > connectTimeout { c.gettyClient.Close() - return nil, perrors.New(fmt.Sprintf("failed to create client connection to %s in %f seconds", addr, float32(times)/1000)) + return nil, perrors.New(fmt.Sprintf("failed to create client connection to %s in %s", addr, connectTimeout)) + } + + interval := time.Millisecond * time.Duration(idx) + if interval > time.Duration(100e6) { + interval = 100e6 // 100 ms } - time.Sleep(time.Millisecond * time.Duration(times)) + time.Sleep(interval) } logger.Debug("client init ok") c.updateActive(time.Now().Unix())