tests: refactor `EtcdProcessClusterConfig` with Functional Options Pattern
remove `cfg *EtcdProcessClusterConfig` param from `NewEtcdProcessCluster` function Signed-off-by: Clark <fwyongxing@gmail.com>dependabot/go_modules/go.uber.org/atomic-1.10.0
parent
9406de0033
commit
7180267d56
|
@ -130,7 +130,7 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCluster(t *testing.T, clusterSize int) *e2e.EtcdProcessCluster {
|
func newCluster(t *testing.T, clusterSize int) *e2e.EtcdProcessCluster {
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithClusterSize(clusterSize),
|
e2e.WithClusterSize(clusterSize),
|
||||||
e2e.WithKeepDataDir(true),
|
e2e.WithKeepDataDir(true),
|
||||||
)
|
)
|
||||||
|
|
|
@ -102,7 +102,7 @@ func TestPeriodicCheckDetectsCorruption(t *testing.T) {
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
epc, err := e2e.NewEtcdProcessCluster(ctx, t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(ctx, t,
|
||||||
e2e.WithKeepDataDir(true),
|
e2e.WithKeepDataDir(true),
|
||||||
e2e.WithCorruptCheckTime(time.Second),
|
e2e.WithCorruptCheckTime(time.Second),
|
||||||
)
|
)
|
||||||
|
@ -149,7 +149,7 @@ func TestCompactHashCheckDetectCorruption(t *testing.T) {
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
epc, err := e2e.NewEtcdProcessCluster(ctx, t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(ctx, t,
|
||||||
e2e.WithKeepDataDir(true),
|
e2e.WithKeepDataDir(true),
|
||||||
e2e.WithCompactHashCheckEnabled(true),
|
e2e.WithCompactHashCheckEnabled(true),
|
||||||
e2e.WithCompactHashCheckTime(checkTime),
|
e2e.WithCompactHashCheckTime(checkTime),
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestAuthCluster(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(ctx, t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(ctx, t,
|
||||||
e2e.WithClusterSize(1),
|
e2e.WithClusterSize(1),
|
||||||
e2e.WithSnapshotCount(2),
|
e2e.WithSnapshotCount(2),
|
||||||
)
|
)
|
||||||
|
|
|
@ -91,7 +91,7 @@ func TestAuthority(t *testing.T) {
|
||||||
// Enable debug mode to get logs with http2 headers (including authority)
|
// Enable debug mode to get logs with http2 headers (including authority)
|
||||||
cfg.EnvVars = map[string]string{"GODEBUG": "http2debug=2"}
|
cfg.EnvVars = map[string]string{"GODEBUG": "http2debug=2"}
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not start etcd process cluster (%v)", err)
|
t.Fatalf("could not start etcd process cluster (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ func testMirrorCommand(cx ctlCtx, flags []string, sourcekvs []kv, destkvs []kvEx
|
||||||
dialTimeout: 7 * time.Second,
|
dialTimeout: 7 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
mirrorepc, err := e2e.NewEtcdProcessCluster(context.TODO(), cx.t, &mirrorctx.cfg)
|
mirrorepc, err := e2e.NewEtcdProcessCluster(context.TODO(), cx.t, e2e.WithConfig(&mirrorctx.cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cx.t.Fatalf("could not start etcd process cluster (%v)", err)
|
cx.t.Fatalf("could not start etcd process cluster (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ func setupEtcdctlTest(t *testing.T, cfg *e2e.EtcdProcessClusterConfig, quorum bo
|
||||||
if !quorum {
|
if !quorum {
|
||||||
cfg = e2e.ConfigStandalone(*cfg)
|
cfg = e2e.ConfigStandalone(*cfg)
|
||||||
}
|
}
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not start etcd process cluster (%v)", err)
|
t.Fatalf("could not start etcd process cluster (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ func testIssue6361(t *testing.T) {
|
||||||
|
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithClusterSize(1),
|
e2e.WithClusterSize(1),
|
||||||
e2e.WithKeepDataDir(true),
|
e2e.WithKeepDataDir(true),
|
||||||
)
|
)
|
||||||
|
|
|
@ -57,7 +57,7 @@ func TestClusterVersion(t *testing.T) {
|
||||||
e2e.WithRollingStart(tt.rollingStart),
|
e2e.WithRollingStart(tt.rollingStart),
|
||||||
)
|
)
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not start etcd process cluster (%v)", err)
|
t.Fatalf("could not start etcd process cluster (%v)", err)
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ func testCtlWithOffline(t *testing.T, testFunc func(ctlCtx), testOfflineFunc fun
|
||||||
ret.cfg.KeepDataDir = true
|
ret.cfg.KeepDataDir = true
|
||||||
}
|
}
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &ret.cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(&ret.cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not start etcd process cluster (%v)", err)
|
t.Fatalf("could not start etcd process cluster (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
|
||||||
t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease)
|
t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
dc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithBasePort(2000),
|
e2e.WithBasePort(2000),
|
||||||
e2e.WithVersion(e2e.LastVersion),
|
e2e.WithVersion(e2e.LastVersion),
|
||||||
e2e.WithClusterSize(1),
|
e2e.WithClusterSize(1),
|
||||||
|
@ -61,7 +61,7 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
c, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
c, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithBasePort(3000),
|
e2e.WithBasePort(3000),
|
||||||
e2e.WithClusterSize(size),
|
e2e.WithClusterSize(size),
|
||||||
e2e.WithIsPeerTLS(peerTLS),
|
e2e.WithIsPeerTLS(peerTLS),
|
||||||
|
|
|
@ -48,7 +48,7 @@ func testClusterUsingV3Discovery(t *testing.T, discoveryClusterSize, targetClust
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
|
|
||||||
// step 1: start the discovery service
|
// step 1: start the discovery service
|
||||||
ds, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
ds, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithBasePort(2000),
|
e2e.WithBasePort(2000),
|
||||||
e2e.WithClusterSize(discoveryClusterSize),
|
e2e.WithClusterSize(discoveryClusterSize),
|
||||||
e2e.WithClientTLS(clientTlsType),
|
e2e.WithClientTLS(clientTlsType),
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestGrpcProxyAutoSync(t *testing.T) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(ctx, t, nil, e2e.WithClusterSize(1))
|
epc, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithClusterSize(1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.NoError(t, epc.Close())
|
assert.NoError(t, epc.Close())
|
||||||
|
|
|
@ -66,7 +66,7 @@ func mixVersionsSnapshotTest(t *testing.T, clusterVersion, newInstanceVersion e2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an etcd cluster with 1 member
|
// Create an etcd cluster with 1 member
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithClusterSize(1),
|
e2e.WithClusterSize(1),
|
||||||
e2e.WithSnapshotCount(10),
|
e2e.WithSnapshotCount(10),
|
||||||
e2e.WithVersion(clusterVersion),
|
e2e.WithVersion(clusterVersion),
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestReleaseUpgrade(t *testing.T) {
|
||||||
|
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithVersion(e2e.LastVersion),
|
e2e.WithVersion(e2e.LastVersion),
|
||||||
e2e.WithSnapshotCount(3),
|
e2e.WithSnapshotCount(3),
|
||||||
e2e.WithBaseScheme("unix"), // to avoid port conflict
|
e2e.WithBaseScheme("unix"), // to avoid port conflict
|
||||||
|
@ -117,7 +117,7 @@ func TestReleaseUpgradeWithRestart(t *testing.T) {
|
||||||
|
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithVersion(e2e.LastVersion),
|
e2e.WithVersion(e2e.LastVersion),
|
||||||
e2e.WithSnapshotCount(10),
|
e2e.WithSnapshotCount(10),
|
||||||
e2e.WithBaseScheme("unix"),
|
e2e.WithBaseScheme("unix"),
|
||||||
|
|
|
@ -28,7 +28,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGateway(t *testing.T) {
|
func TestGateway(t *testing.T) {
|
||||||
ec, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.NewConfigNoTLS())
|
ec, err := e2e.NewEtcdProcessCluster(context.TODO(), t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ func TestEtctlutlMigrate(t *testing.T) {
|
||||||
}
|
}
|
||||||
dataDirPath := t.TempDir()
|
dataDirPath := t.TempDir()
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithVersion(tc.clusterVersion),
|
e2e.WithVersion(tc.clusterVersion),
|
||||||
e2e.WithDataDirPath(dataDirPath),
|
e2e.WithDataDirPath(dataDirPath),
|
||||||
e2e.WithClusterSize(1),
|
e2e.WithClusterSize(1),
|
||||||
|
|
|
@ -41,7 +41,7 @@ func createV2store(t testing.TB, dataDirPath string) string {
|
||||||
e2e.WithDataDirPath(dataDirPath),
|
e2e.WithDataDirPath(dataDirPath),
|
||||||
e2e.WithSnapshotCount(5),
|
e2e.WithSnapshotCount(5),
|
||||||
))
|
))
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
memberDataDir := epc.Procs[0].Config().DataDirPath
|
memberDataDir := epc.Procs[0].Config().DataDirPath
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) {
|
||||||
e2e.WithVersion(e2e.CurrentVersion),
|
e2e.WithVersion(e2e.CurrentVersion),
|
||||||
e2e.WithDataDirPath(dataDir),
|
e2e.WithDataDirPath(dataDir),
|
||||||
))
|
))
|
||||||
epc, err = e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err = e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
cc, err = e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
|
cc, err = e2e.NewEtcdctl(epc.Cfg, epc.EndpointsV3())
|
||||||
|
@ -188,7 +188,7 @@ func runEtcdAndCreateSnapshot(t testing.TB, serverVersion e2e.ClusterVersion, da
|
||||||
e2e.WithSnapshotCount(snapshotCount),
|
e2e.WithSnapshotCount(snapshotCount),
|
||||||
e2e.WithKeepDataDir(true),
|
e2e.WithKeepDataDir(true),
|
||||||
))
|
))
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(cfg))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return epc
|
return epc
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ func testV3CurlMaxStream(t *testing.T, reachLimit bool, opts ...ctlOption) {
|
||||||
|
|
||||||
// Step 2: create the cluster
|
// Step 2: create the cluster
|
||||||
t.Log("Creating an etcd cluster")
|
t.Log("Creating an etcd cluster")
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &cx.cfg)
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(&cx.cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to start etcd cluster: %v", err)
|
t.Fatalf("Failed to start etcd cluster: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import (
|
||||||
func TestServerJsonLogging(t *testing.T) {
|
func TestServerJsonLogging(t *testing.T) {
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
|
|
||||||
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, nil,
|
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t,
|
||||||
e2e.WithClusterSize(1),
|
e2e.WithClusterSize(1),
|
||||||
e2e.WithLogLevel("debug"),
|
e2e.WithLogLevel("debug"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -312,14 +312,8 @@ func WithCompactionBatchLimit(limit int) EPClusterOption {
|
||||||
|
|
||||||
// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
|
// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
|
||||||
// a new EtcdProcessCluster once all nodes are ready to accept client requests.
|
// a new EtcdProcessCluster once all nodes are ready to accept client requests.
|
||||||
func NewEtcdProcessCluster(ctx context.Context, t testing.TB, cfg *EtcdProcessClusterConfig, opts ...EPClusterOption) (*EtcdProcessCluster, error) {
|
func NewEtcdProcessCluster(ctx context.Context, t testing.TB, opts ...EPClusterOption) (*EtcdProcessCluster, error) {
|
||||||
if cfg == nil {
|
cfg := NewConfig(opts...)
|
||||||
cfg = NewConfig(opts...)
|
|
||||||
} else {
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(cfg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
epc, err := InitEtcdProcessCluster(t, cfg)
|
epc, err := InitEtcdProcessCluster(t, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -86,7 +86,7 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
|
||||||
default:
|
default:
|
||||||
t.Fatalf("PeerTLS config %q not supported", cfg.PeerTLS)
|
t.Fatalf("PeerTLS config %q not supported", cfg.PeerTLS)
|
||||||
}
|
}
|
||||||
epc, err := NewEtcdProcessCluster(ctx, t, e2eConfig)
|
epc, err := NewEtcdProcessCluster(ctx, t, WithConfig(e2eConfig))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not start etcd integrationCluster: %s", err)
|
t.Fatalf("could not start etcd integrationCluster: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ func TestLinearizability(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLinearizability(ctx context.Context, t *testing.T, config e2e.EtcdProcessClusterConfig, failpoint FailpointConfig, traffic trafficConfig) {
|
func testLinearizability(ctx context.Context, t *testing.T, config e2e.EtcdProcessClusterConfig, failpoint FailpointConfig, traffic trafficConfig) {
|
||||||
clus, err := e2e.NewEtcdProcessCluster(ctx, t, &config)
|
clus, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(&config))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue