From e59c00b1af96544230243dfb2f88b8f14d2968a1 Mon Sep 17 00:00:00 2001 From: lzp0412 <641785844@qq.com> Date: Tue, 21 Jul 2020 19:32:08 +0800 Subject: [PATCH] solve nacos unit test failed --- registry/nacos/service_discovery_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/registry/nacos/service_discovery_test.go b/registry/nacos/service_discovery_test.go index 720c44a6f..4b069c2e8 100644 --- a/registry/nacos/service_discovery_test.go +++ b/registry/nacos/service_discovery_test.go @@ -18,7 +18,10 @@ package nacos import ( + "math/rand" + "strconv" "testing" + "time" ) import ( @@ -84,8 +87,8 @@ func TestNacosServiceDiscovery_CRUD(t *testing.T) { }) extension.SetAndInitGlobalDispatcher("mock") - - serviceName := "service-name" + rand.Seed(time.Now().Unix()) + serviceName := "service-name" + strconv.Itoa(rand.Intn(10000)) id := "id" host := "host" port := 123 @@ -113,7 +116,9 @@ func TestNacosServiceDiscovery_CRUD(t *testing.T) { err := serviceDiscovry.Register(instance) assert.Nil(t, err) - + //sometimes nacos may be failed to push update of instance, + //so it need 10s to pull, we sleep 10 second to make sure instance has been update + time.Sleep(11 * time.Second) page := serviceDiscovry.GetHealthyInstancesByPage(serviceName, 0, 10, true) assert.NotNil(t, page) -- GitLab