diff --git a/cluster/router/conncheck/conn_check_route_test.go b/cluster/router/conncheck/conn_check_route_test.go index 9c78fd3899488df0ae82cfa0c2dbac71c51b1fa6..95b8d4a928b7ee92d0d2cf9d5e8f8f62442e77d0 100644 --- a/cluster/router/conncheck/conn_check_route_test.go +++ b/cluster/router/conncheck/conn_check_route_test.go @@ -19,8 +19,9 @@ package conncheck import ( "fmt" + "github.com/apache/dubbo-go/protocol/mock" + "github.com/golang/mock/gomock" "testing" - "time" ) import ( @@ -74,12 +75,27 @@ func TestConnCheckRouterRoute(t *testing.T) { // now invoker3 invoker1 is healthy assert.True(t, len(res.ToArray()) == 2) +} + +func TestRecovery(t *testing.T) { // check recover + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + invoker1 := mock.NewMockInvoker(ctrl) + invoker2 := mock.NewMockInvoker(ctrl) + + invoker1.EXPECT().GetUrl().Return(&common.URL{Path: "path1"}).AnyTimes() + invoker2.EXPECT().GetUrl().Return(&common.URL{Path: "path2"}).AnyTimes() + invoker1.EXPECT().IsAvailable().Return(true).AnyTimes() + invoker2.EXPECT().IsAvailable().Return(true).AnyTimes() + + protocol.SetInvokerUnhealthyStatus(invoker1) + protocol.SetInvokerUnhealthyStatus(invoker2) + assert.Equal(t, len(protocol.GetBlackListInvokers(16)), 2) protocol.TryRefreshBlackList() - time.Sleep(time.Second) - res = hcr.Route(utils.ToBitmap(invokers), setUpAddrCache(hcr.(*ConnCheckRouter), invokers), consumerURL, inv) - // now all invokers are healthy - assert.True(t, len(res.ToArray()) == 3) + assert.Equal(t, len(protocol.GetBlackListInvokers(16)), 0) } func setUpAddrCache(r router.Poolable, addrs []protocol.Invoker) router.Cache { diff --git a/protocol/rpc_status.go b/protocol/rpc_status.go index 1e0b311e27700bfecc49f8daf7a2d9ca3fb90944..72ad34460d7a3650118616e79f46893170a2e50b 100644 --- a/protocol/rpc_status.go +++ b/protocol/rpc_status.go @@ -241,6 +241,7 @@ func TryRefreshBlackList() { for i := 0; i < 3; i++ { wg.Add(1) go func(ivks []Invoker, i int) { + defer wg.Done() for j, _ := range ivks { if j%3-i == 0 { if ivks[j].(Invoker).IsAvailable() {