From 7dfa6be2738f6ee80cb92a6df73337cbcee546ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E4=BF=A1?=
 <lizhixin@B-C0A1LVDL-2144.local>
Date: Mon, 28 Dec 2020 15:24:48 +0800
Subject: [PATCH] fix: add health check test file

---
 .../router/conncheck/conn_check_route_test.go | 26 +++++++++++++++----
 protocol/rpc_status.go                        |  1 +
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/cluster/router/conncheck/conn_check_route_test.go b/cluster/router/conncheck/conn_check_route_test.go
index 9c78fd389..95b8d4a92 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 1e0b311e2..72ad34460 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() {
-- 
GitLab