Skip to content
Snippets Groups Projects
Commit a82ebbcd authored by 李志信's avatar 李志信
Browse files

fix: add health check test file

parent 45cef6f3
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,9 @@ package conncheck ...@@ -19,8 +19,9 @@ package conncheck
import ( import (
"fmt" "fmt"
"github.com/apache/dubbo-go/protocol/mock"
"github.com/golang/mock/gomock"
"testing" "testing"
"time"
) )
import ( import (
...@@ -74,12 +75,27 @@ func TestConnCheckRouterRoute(t *testing.T) { ...@@ -74,12 +75,27 @@ func TestConnCheckRouterRoute(t *testing.T) {
// now invoker3 invoker1 is healthy // now invoker3 invoker1 is healthy
assert.True(t, len(res.ToArray()) == 2) assert.True(t, len(res.ToArray()) == 2)
}
func TestRecovery(t *testing.T) {
// check recover // 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() protocol.TryRefreshBlackList()
time.Sleep(time.Second) assert.Equal(t, len(protocol.GetBlackListInvokers(16)), 0)
res = hcr.Route(utils.ToBitmap(invokers), setUpAddrCache(hcr.(*ConnCheckRouter), invokers), consumerURL, inv)
// now all invokers are healthy
assert.True(t, len(res.ToArray()) == 3)
} }
func setUpAddrCache(r router.Poolable, addrs []protocol.Invoker) router.Cache { func setUpAddrCache(r router.Poolable, addrs []protocol.Invoker) router.Cache {
......
...@@ -241,6 +241,7 @@ func TryRefreshBlackList() { ...@@ -241,6 +241,7 @@ func TryRefreshBlackList() {
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
wg.Add(1) wg.Add(1)
go func(ivks []Invoker, i int) { go func(ivks []Invoker, i int) {
defer wg.Done()
for j, _ := range ivks { for j, _ := range ivks {
if j%3-i == 0 { if j%3-i == 0 {
if ivks[j].(Invoker).IsAvailable() { if ivks[j].(Invoker).IsAvailable() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment