diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go index 81432ff2aeee3c6aa06a56a840115c6fc9c83352..1651f72e5c86a49bfd96f789d82f0ab54caaef51 100644 --- a/metadata/report/nacos/report_test.go +++ b/metadata/report/nacos/report_test.go @@ -22,6 +22,7 @@ import ( "net/http" "strconv" "testing" + "time" ) import ( @@ -37,7 +38,7 @@ import ( ) func TestNacosMetadataReport_CRUD(t *testing.T) { - if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil { + if !checkNacosServerAlive() { return } rpt := newTestReport() @@ -118,3 +119,11 @@ func newTestReport() report.MetadataReport { res := extension.GetMetadataReportFactory("nacos").CreateMetadataReport(®url) return res } + +func checkNacosServerAlive() bool { + c := http.Client{Timeout: time.Second} + if _, err := c.Get("http://console.nacos.io/nacos/"); err != nil { + return false + } + return true +} diff --git a/registry/nacos/registry_test.go b/registry/nacos/registry_test.go index a07b41941701c4d615f17955c666c4bb8bea8013..473733b449f09897d80b278c4bbac1a711026442 100644 --- a/registry/nacos/registry_test.go +++ b/registry/nacos/registry_test.go @@ -23,6 +23,7 @@ import ( "net/url" "strconv" "testing" + "time" ) import ( @@ -36,7 +37,7 @@ import ( ) func TestNacosRegistry_Register(t *testing.T) { - if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil { + if !checkNacosServerAlive() { return } regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) @@ -68,7 +69,7 @@ func TestNacosRegistry_Register(t *testing.T) { } func TestNacosRegistry_Subscribe(t *testing.T) { - if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil { + if !checkNacosServerAlive() { return } regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) @@ -109,7 +110,7 @@ func TestNacosRegistry_Subscribe(t *testing.T) { } func TestNacosRegistry_Subscribe_del(t *testing.T) { - if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil { + if !checkNacosServerAlive() { return } regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) @@ -198,3 +199,11 @@ func TestNacosListener_Close(t *testing.T) { _, err = listener.Next() assert.NotNil(t, err) } + +func checkNacosServerAlive() bool { + c := http.Client{Timeout: time.Second} + if _, err := c.Get("http://console.nacos.io/nacos/"); err != nil { + return false + } + return true +} diff --git a/registry/nacos/service_discovery_test.go b/registry/nacos/service_discovery_test.go index 0628e991ae64c3a0ba44dc24b606826d7724c01e..3b09136d2e273090bea339e0a15b25dde719b6ac 100644 --- a/registry/nacos/service_discovery_test.go +++ b/registry/nacos/service_discovery_test.go @@ -19,7 +19,6 @@ package nacos import ( "math/rand" - "net/http" "strconv" "testing" "time" @@ -82,7 +81,7 @@ func TestNacosServiceDiscovery_Destroy(t *testing.T) { } func TestNacosServiceDiscovery_CRUD(t *testing.T) { - if _, err := http.Get("http://console.nacos.io/nacos/"); err != nil { + if !checkNacosServerAlive() { return } prepareData()