From c3d0bb66bb481b6ec853fd7d11de3673127f7455 Mon Sep 17 00:00:00 2001 From: wangcong <497272486@qq.com> Date: Sat, 6 Nov 2021 15:15:56 +0800 Subject: [PATCH] fix: nacos registry test data race (#1613) --- contrib/config/nacos/config_test.go | 3 ++- contrib/registry/nacos/registry_test.go | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/contrib/config/nacos/config_test.go b/contrib/config/nacos/config_test.go index 02f44b16b..9065ac91f 100644 --- a/contrib/config/nacos/config_test.go +++ b/contrib/config/nacos/config_test.go @@ -6,11 +6,12 @@ import ( "testing" "time" - kconfig "github.com/go-kratos/kratos/v2/config" "github.com/nacos-group/nacos-sdk-go/clients" "github.com/nacos-group/nacos-sdk-go/common/constant" "github.com/nacos-group/nacos-sdk-go/vo" "gopkg.in/yaml.v3" + + kconfig "github.com/go-kratos/kratos/v2/config" ) func getIntranetIP() string { diff --git a/contrib/registry/nacos/registry_test.go b/contrib/registry/nacos/registry_test.go index 800bec466..62765b0cc 100644 --- a/contrib/registry/nacos/registry_test.go +++ b/contrib/registry/nacos/registry_test.go @@ -7,10 +7,11 @@ import ( "testing" "time" - "github.com/go-kratos/kratos/v2/registry" "github.com/nacos-group/nacos-sdk-go/clients" "github.com/nacos-group/nacos-sdk-go/common/constant" "github.com/nacos-group/nacos-sdk-go/vo" + + "github.com/go-kratos/kratos/v2/registry" ) func getIntranetIP() string { @@ -88,15 +89,18 @@ func TestRegistry(t *testing.T) { r := New(client) go func() { - var w registry.Watcher - w, err = r.Watch(ctx, "golang-sms@grpc") - if err != nil { - log.Fatal(err) + var ( + w registry.Watcher + watchErr error + ) + w, watchErr = r.Watch(ctx, "golang-sms@grpc") + if watchErr != nil { + log.Fatal(watchErr) } for { var res []*registry.ServiceInstance - res, err = w.Next() - if err != nil { + res, watchErr = w.Next() + if watchErr != nil { return } log.Printf("watch: %d", len(res))