1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

fix: nacos registry test data race (#1613)

This commit is contained in:
wangcong 2021-11-06 15:15:56 +08:00 committed by GitHub
parent 32272fe441
commit c3d0bb66bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -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 {

View File

@ -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))