Skip to content

Commit

Permalink
Merge pull request #14660 from clarkfw/new-cluster-accept-configurati…
Browse files Browse the repository at this point in the history
…on-as-options

tests: TestRunner.NewCluster accepts options
  • Loading branch information
ahrtr authored Oct 31, 2022
2 parents a1018db + fa9ee5c commit 5073af6
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 44 deletions.
7 changes: 3 additions & 4 deletions tests/common/alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ func TestAlarm(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
cfg := config.NewClusterConfig(
clus := testRunner.NewCluster(ctx, t,
config.WithClusterSize(1),
config.WithQuotaBackendBytes(int64(13*os.Getpagesize())),
)
clus := testRunner.NewCluster(ctx, t, cfg)
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down Expand Up @@ -115,11 +114,11 @@ func TestAlarmlistOnMemberRestart(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(
clus := testRunner.NewCluster(ctx, t,
config.WithClusterSize(1),
config.WithQuotaBackendBytes(int64(13*os.Getpagesize())),
config.WithSnapshotCount(5),
))
)
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down
2 changes: 1 addition & 1 deletion tests/common/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestCompact(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.DefaultClusterConfig())
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down
2 changes: 1 addition & 1 deletion tests/common/defrag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestDefragOnline(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
options := config.DefragOption{Timeout: 10 * time.Second}
clus := testRunner.NewCluster(ctx, t, config.DefaultClusterConfig())
clus := testRunner.NewCluster(ctx, t)
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
defer clus.Close()
Expand Down
7 changes: 3 additions & 4 deletions tests/common/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (
"time"

"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

func TestEndpointStatus(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.DefaultClusterConfig())
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand All @@ -43,7 +42,7 @@ func TestEndpointHashKV(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.DefaultClusterConfig())
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand All @@ -58,7 +57,7 @@ func TestEndpointHealth(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.DefaultClusterConfig())
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down
8 changes: 4 additions & 4 deletions tests/common/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestKVPut(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -66,7 +66,7 @@ func TestKVGet(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -126,7 +126,7 @@ func TestKVDelete(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestKVGetNoQuorum(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.DefaultClusterConfig())
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()

clus.Members()[0].Stop()
Expand Down
10 changes: 5 additions & 5 deletions tests/common/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestLeaseGrantTimeToLive(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -77,7 +77,7 @@ func TestLeaseGrantAndList(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
t.Logf("Creating cluster...")
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
t.Logf("Created cluster and client")
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -161,7 +161,7 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -190,7 +190,7 @@ func TestLeaseGrantRevoke(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down
7 changes: 4 additions & 3 deletions tests/common/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

Expand All @@ -33,7 +34,7 @@ func TestMemberList(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -107,7 +108,7 @@ func TestMemberAdd(t *testing.T) {
defer cancel()
c := clusterTc.config
c.StrictReconfigCheck = quorumTc.strictReconfigCheck
clus := testRunner.NewCluster(ctx, t, c)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(c))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -188,7 +189,7 @@ func TestMemberRemove(t *testing.T) {
defer cancel()
c := clusterTc.config
c.StrictReconfigCheck = quorumTc.strictReconfigCheck
clus := testRunner.NewCluster(ctx, t, c)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(c))
defer clus.Close()
// client connects to a specific member which won't be removed from cluster
cc := clus.Members()[0].Client()
Expand Down
10 changes: 5 additions & 5 deletions tests/common/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestRoleAdd_Simple(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand All @@ -51,7 +51,7 @@ func TestRoleAdd_Error(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(config.WithClusterSize(1)))
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand All @@ -74,7 +74,7 @@ func TestRootRole(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(config.WithClusterSize(1)))
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestRoleGrantRevokePermission(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(config.WithClusterSize(1)))
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestRoleDelete(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(config.WithClusterSize(1)))
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down
3 changes: 2 additions & 1 deletion tests/common/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

Expand All @@ -31,7 +32,7 @@ func TestStatus(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down
4 changes: 2 additions & 2 deletions tests/common/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestTxnSucc(t *testing.T) {
t.Run(cfg.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, cfg.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(cfg.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestTxnFail(t *testing.T) {
t.Run(cfg.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, cfg.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(cfg.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down
10 changes: 5 additions & 5 deletions tests/common/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestUserAdd_Simple(t *testing.T) {
t.Run(tc.name+"/"+nc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -101,7 +101,7 @@ func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -130,7 +130,7 @@ func TestUserList(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -171,7 +171,7 @@ func TestUserDelete(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down Expand Up @@ -223,7 +223,7 @@ func TestUserChangePassword(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())

Expand Down
4 changes: 2 additions & 2 deletions tests/common/wait_leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestWaitLeader(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()

leader := clus.WaitLeader(t)
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestWaitLeader_MemberStop(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()

lead1 := clus.WaitLeader(t)
Expand Down
2 changes: 1 addition & 1 deletion tests/common/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestWatch(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))

defer clus.Close()
cc := framework.MustClient(clus.Client())
Expand Down
8 changes: 6 additions & 2 deletions tests/framework/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func NewClusterConfig(opts ...ClusterOption) ClusterConfig {

type ClusterOption func(*ClusterConfig)

func WithClusterConfig(cfg ClusterConfig) ClusterOption {
return func(c *ClusterConfig) { *c = cfg }
}

func WithClusterSize(size int) ClusterOption {
return func(c *ClusterConfig) { c.ClusterSize = size }
}
Expand All @@ -73,6 +77,6 @@ func WithSnapshotCount(count int) ClusterOption {
return func(c *ClusterConfig) { c.SnapshotCount = count }
}

func WithDisableStrictReconfigCheck() ClusterOption {
return func(c *ClusterConfig) { c.StrictReconfigCheck = false }
func WithStrictReconfigCheck(strict bool) ClusterOption {
return func(c *ClusterConfig) { c.StrictReconfigCheck = strict }
}
3 changes: 2 additions & 1 deletion tests/framework/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func (e e2eRunner) BeforeTest(t testing.TB) {
e2e.BeforeTest(t)
}

func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, cfg config.ClusterConfig) Cluster {
func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) Cluster {
cfg := config.NewClusterConfig(opts...)
e2eConfig := e2e.EtcdProcessClusterConfig{
InitialToken: "new",
ClusterSize: cfg.ClusterSize,
Expand Down
3 changes: 2 additions & 1 deletion tests/framework/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func (e integrationRunner) BeforeTest(t testing.TB) {
integration.BeforeTest(t)
}

func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, cfg config.ClusterConfig) Cluster {
func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) Cluster {
var err error
cfg := config.NewClusterConfig(opts...)
integrationCfg := integration.ClusterConfig{
Size: cfg.ClusterSize,
QuotaBackendBytes: cfg.QuotaBackendBytes,
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type TestRunner interface {
TestMain(m *testing.M)
BeforeTest(testing.TB)
NewCluster(context.Context, testing.TB, config.ClusterConfig) Cluster
NewCluster(context.Context, testing.TB, ...config.ClusterOption) Cluster
}

type Cluster interface {
Expand Down
Loading

0 comments on commit 5073af6

Please sign in to comment.