diff --git a/tests/integration/v2store/main_test.go b/tests/integration/v2store/main_test.go index a11f6c32b..eb1fc665a 100644 --- a/tests/integration/v2store/main_test.go +++ b/tests/integration/v2store/main_test.go @@ -15,30 +15,26 @@ package v2store_test import ( - "fmt" - "os" "testing" - "time" "go.etcd.io/etcd/pkg/v3/testutil" - "go.etcd.io/etcd/tests/v3/integration" ) -var endpoints []string +//var endpoints []string -// TestMain sets up an etcd cluster for running the examples. func TestMain(m *testing.M) { - cfg := integration.ClusterConfig{Size: 1} - clus := integration.NewClusterV3(nil, &cfg) - endpoints = []string{clus.Client(0).Endpoints()[0]} - v := m.Run() - clus.Terminate(nil) - if err := testutil.CheckAfterTest(time.Second); err != nil { - fmt.Fprintf(os.Stderr, "%v", err) - os.Exit(1) - } - if v == 0 && testutil.CheckLeakedGoroutine() { - os.Exit(1) - } - os.Exit(v) + //cfg := integration.ClusterConfig{Size: 1} + //clus := integration.NewClusterV3(nil, &cfg) + //endpoints = []string{clus.Client(0).Endpoints()[0]} + // v := m.Run() + //clus.Terminate(nil) + //if err := testutil.CheckAfterTest(time.Second); err != nil { + // fmt.Fprintf(os.Stderr, "%v", err) + // os.Exit(1) + //} + testutil.MustTestMainWithLeakDetection(m) + //if v == 0 && testutil.CheckLeakedGoroutine() { + // os.Exit(1) + //} + //os.Exit(v) } diff --git a/tests/integration/v2store/store_v2v3_test.go b/tests/integration/v2store/store_v2v3_test.go index 7249102b8..d734f284d 100644 --- a/tests/integration/v2store/store_v2v3_test.go +++ b/tests/integration/v2store/store_v2v3_test.go @@ -19,13 +19,27 @@ import ( "testing" "go.etcd.io/etcd/client/v3" + "go.etcd.io/etcd/pkg/v3/testutil" "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" "go.etcd.io/etcd/server/v3/etcdserver/api/v2v3" + "go.etcd.io/etcd/tests/v3/integration" ) // TODO: fix tests -func TestCreateKV(t *testing.T) { +func runWithCluster(t testing.TB, runner func(testing.TB, []string)) { + testutil.BeforeTest(t) + cfg := integration.ClusterConfig{Size: 1} + clus := integration.NewClusterV3(nil, &cfg) + defer clus.Terminate(t) + endpoints := []string{clus.Client(0).Endpoints()[0]} + runner(t, endpoints) + +} + +func TestCreateKV(t *testing.T) { runWithCluster(t, testCreateKV) } + +func testCreateKV(t testing.TB, endpoints []string) { testCases := []struct { key string value string @@ -77,7 +91,9 @@ func TestCreateKV(t *testing.T) { } } -func TestSetKV(t *testing.T) { +func TestSetKV(t *testing.T) { runWithCluster(t, testSetKV) } + +func testSetKV(t testing.TB, endpoints []string) { testCases := []struct { key string value string @@ -113,7 +129,9 @@ func TestSetKV(t *testing.T) { } } -func TestCreateSetDir(t *testing.T) { +func TestCreateSetDir(t *testing.T) { runWithCluster(t, testCreateSetDir) } + +func testCreateSetDir(t testing.TB, endpoints []string) { testCases := []struct { dir string }{