diff --git a/registry/etcdv3/listener_test.go b/registry/etcdv3/listener_test.go index 56564736465c733ec13d9d18e02bd01bb12e8698..a36d89bea53607cd3fe0c2cbff33848d735c4fb6 100644 --- a/registry/etcdv3/listener_test.go +++ b/registry/etcdv3/listener_test.go @@ -11,7 +11,7 @@ import ( "github.com/apache/dubbo-go/remoting" ) -func startETCDServer(t *testing.T) { +func startETCDServer() { cmd := exec.Command("./load.sh", "start") //cmd := exec.Command("pwd") @@ -20,12 +20,12 @@ func startETCDServer(t *testing.T) { cmd.Dir = "../../remoting/etcdv3/single" if err := cmd.Run(); err != nil { - t.Fatal(err) + panic(err) } } -func stopETCDServer(t *testing.T) { +func stopETCDServer() { cmd := exec.Command("./load.sh", "stop") //cmd := exec.Command("pwd") @@ -34,15 +34,19 @@ func stopETCDServer(t *testing.T) { cmd.Dir = "../../remoting/etcdv3/single" if err := cmd.Run(); err != nil { - t.Fatal(err) + panic(err) } } -func Test_DataChange(t *testing.T) { +func TestMain(m *testing.M) { + + startETCDServer() + m.Run() + stopETCDServer() +} - startETCDServer(t) - defer stopETCDServer(t) +func Test_DataChange(t *testing.T) { listener := NewRegistryDataListener(&MockDataListener{}) url, _ := common.NewURL(context.TODO(), "jsonrpc%3A%2F%2F127.0.0.1%3A20001%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26app.version%3D0.0.1%26application%3DBDTService%26category%3Dproviders%26cluster%3Dfailover%26dubbo%3Ddubbo-provider-golang-2.6.0%26environment%3Ddev%26group%3D%26interface%3Dcom.ikurento.user.UserProvider%26ip%3D10.32.20.124%26loadbalance%3Drandom%26methods.GetUser.loadbalance%3Drandom%26methods.GetUser.retries%3D1%26methods.GetUser.weight%3D0%26module%3Ddubbogo%2Buser-info%2Bserver%26name%3DBDTService%26organization%3Dikurento.com%26owner%3DZX%26pid%3D74500%26retries%3D0%26service.filter%3Decho%26side%3Dprovider%26timestamp%3D1560155407%26version%3D%26warmup%3D100") diff --git a/registry/etcdv3/registry_test.go b/registry/etcdv3/registry_test.go index 81a8e0ddb6c4e86a7b769c3234be2c27991230a2..c235f104e17eb2fc61173ba3f65056e43215e908 100644 --- a/registry/etcdv3/registry_test.go +++ b/registry/etcdv3/registry_test.go @@ -35,9 +35,6 @@ func initRegistry(t *testing.T) *etcdV3Registry { func Test_Register(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) reg := initRegistry(t) @@ -52,9 +49,6 @@ func Test_Register(t *testing.T) { func Test_Subscribe(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) @@ -84,9 +78,6 @@ func Test_Subscribe(t *testing.T) { func Test_ConsumerDestory(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) reg := initRegistry(t) @@ -105,9 +96,6 @@ func Test_ConsumerDestory(t *testing.T) { func Test_ProviderDestory(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - reg := initRegistry(t) url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) reg.Register(url) diff --git a/remoting/etcdv3/client_test.go b/remoting/etcdv3/client_test.go index 3d586a8bb2955d61f7dde9a5bdd73db066b93a51..00bbfbb57beb03ff44184b3ea99c768f628d937d 100644 --- a/remoting/etcdv3/client_test.go +++ b/remoting/etcdv3/client_test.go @@ -61,7 +61,14 @@ func initClient(t *testing.T) *Client { return c } -func startETCDServer(t *testing.T) { +func TestMain(m *testing.M) { + + startETCDServer() + m.Run() + stopETCDServer() +} + +func startETCDServer() { cmd := exec.Command("./load.sh", "start") cmd.Stdout = os.Stdout @@ -69,27 +76,24 @@ func startETCDServer(t *testing.T) { cmd.Dir = "./single" if err := cmd.Run(); err != nil { - t.Fatal(err) + panic(err) } } -func stopETCDServer(t *testing.T) { +func stopETCDServer() { cmd := exec.Command("./load.sh", "stop") cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout cmd.Dir = "./single" if err := cmd.Run(); err != nil { - t.Fatal(err) + panic(err) } } func Test_newClient(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - c := initClient(t) defer c.Close() @@ -100,18 +104,12 @@ func Test_newClient(t *testing.T) { func TestClient_Close(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - c := initClient(t) c.Close() } func TestClient_Create(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - tests := tests c := initClient(t) @@ -143,9 +141,6 @@ func TestClient_Create(t *testing.T) { func TestClient_Delete(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - tests := tests c := initClient(t) @@ -179,9 +174,6 @@ func TestClient_Delete(t *testing.T) { func TestClient_GetChildrenKVList(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - tests := tests c := initClient(t) @@ -220,9 +212,6 @@ func TestClient_GetChildrenKVList(t *testing.T) { func TestClient_Watch(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - tests := tests c := initClient(t) @@ -275,9 +264,6 @@ func TestClient_Watch(t *testing.T) { func TestClient_RegisterTemp(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - c := initClient(t) observeC := initClient(t) @@ -322,9 +308,6 @@ func TestClient_RegisterTemp(t *testing.T) { func TestClient_Valid(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - c := initClient(t) if c.Valid() != true { @@ -343,9 +326,6 @@ func TestClient_Valid(t *testing.T) { func TestClient_Done(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - c := initClient(t) go func() { diff --git a/remoting/etcdv3/facede_test.go b/remoting/etcdv3/facede_test.go index d7ba1cef7b48eb6de680834cd460c5174f57005e..590d30dc2fade430ce4d2f961e008faac8718042 100644 --- a/remoting/etcdv3/facede_test.go +++ b/remoting/etcdv3/facede_test.go @@ -55,9 +55,6 @@ func (r *mockFacade) IsAvailable() bool { func Test_Fascade(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - c := initClient(t) url, err := common.NewURL(context.Background(), "mock://127.0.0.1:2379") diff --git a/remoting/etcdv3/listener_test.go b/remoting/etcdv3/listener_test.go index 4dd6e7f318a978dc610784bc15c4be6d82ef60ed..22f8b70889faee52e9d3ee5571f03a77a02446f7 100644 --- a/remoting/etcdv3/listener_test.go +++ b/remoting/etcdv3/listener_test.go @@ -32,9 +32,6 @@ var changedData = ` func TestListener(t *testing.T) { - startETCDServer(t) - defer stopETCDServer(t) - var tests = []struct { input struct { k string