From 2a924dcb5baec4a7bfa41df4fd50236a53741752 Mon Sep 17 00:00:00 2001 From: Joe Zou Date: Fri, 11 Dec 2020 18:10:46 +0800 Subject: [PATCH 1/2] Trigger init router for first call --- cluster/router/chain/chain.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cluster/router/chain/chain.go b/cluster/router/chain/chain.go index 612c12d87d..f55cd07bc9 100644 --- a/cluster/router/chain/chain.go +++ b/cluster/router/chain/chain.go @@ -65,6 +65,8 @@ type RouterChain struct { notify chan struct{} // Address cache cache atomic.Value + // init + init sync.Once } // Route Loop routers in RouterChain and call Route method to determine the target invokers list. @@ -111,6 +113,13 @@ func (c *RouterChain) SetInvokers(invokers []protocol.Invoker) { c.invokers = invokers c.mutex.Unlock() + // it should trigger init router for first call + c.init.Do(func() { + go func() { + c.notify <- struct{}{} + }() + }) + c.count++ now := time.Now() if c.count >= countThreshold && now.Sub(c.last) >= timeThreshold { From 329710aee392751e67269025e349d5fae269a10b Mon Sep 17 00:00:00 2001 From: Joe Zou Date: Fri, 11 Dec 2020 18:37:14 +0800 Subject: [PATCH 2/2] Test case should wait for next loop to build chain chain in each 5 seconds --- registry/directory/directory_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/directory/directory_test.go b/registry/directory/directory_test.go index dde944d624..9008e6ecb7 100644 --- a/registry/directory/directory_test.go +++ b/registry/directory/directory_test.go @@ -124,7 +124,7 @@ func Test_Destroy(t *testing.T) { func Test_List(t *testing.T) { registryDirectory, _ := normalRegistryDir() - time.Sleep(4e9) + time.Sleep(6e9) assert.Len(t, registryDirectory.List(&invocation.RPCInvocation{}), 3) assert.Equal(t, true, registryDirectory.IsAvailable())