Tests: Better isolation between store_v2v3 integration tests.

This commit is contained in:
Piotr Tabor 2021-03-07 01:25:37 +01:00
parent fb1d48e98e
commit 41f6cc7234
2 changed files with 36 additions and 22 deletions

View File

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

View File

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