Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix anti-pattern naming problem in config.ClusterConfig #14629

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/common/alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAlarm(t *testing.T) {
testRunner.BeforeTest(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 1, QuotaBackendBytes: int64(13 * os.Getpagesize())})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(1, config.WithQuotaBackendBytes(int64(13*os.Getpagesize()))))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down Expand Up @@ -111,11 +111,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.ClusterConfig{
ClusterSize: 1,
QuotaBackendBytes: int64(13 * os.Getpagesize()),
SnapshotCount: 5,
})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(
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.ClusterConfig{ClusterSize: 3})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(3))
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.ClusterConfig{ClusterSize: 3})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(3))
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
defer clus.Close()
Expand Down
6 changes: 3 additions & 3 deletions tests/common/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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.ClusterConfig{ClusterSize: 3})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(3))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand All @@ -43,7 +43,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.ClusterConfig{ClusterSize: 3})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(3))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand All @@ -58,7 +58,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.ClusterConfig{ClusterSize: 3})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(3))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
Expand Down
2 changes: 1 addition & 1 deletion tests/common/kv_test.go
Original file line number Diff line number Diff line change
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.ClusterConfig{ClusterSize: 3})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(3))
defer clus.Close()

clus.Members()[0].Stop()
Expand Down
27 changes: 1 addition & 26 deletions tests/common/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,7 @@ import (
func TestLeaseGrantTimeToLive(t *testing.T) {
testRunner.BeforeTest(t)

tcs := []struct {
name string
config config.ClusterConfig
}{
{
name: "NoTLS",
config: config.ClusterConfig{ClusterSize: 1},
},
{
name: "PeerTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
},
{
name: "PeerAutoTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
},
{
name: "ClientTLS",
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS},
},
{
name: "ClientAutoTLS",
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS},
},
}
for _, tc := range tcs {
for _, tc := range clusterTestCases {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down
10 changes: 5 additions & 5 deletions tests/common/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ var testRunner = framework.UnitTestRunner
var clusterTestCases = []testCase{
{
name: "NoTLS",
config: config.ClusterConfig{ClusterSize: 1},
config: config.NewClusterConfig(1),
},
{
name: "PeerTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
config: config.NewClusterConfig(3, config.WithPeerTLS(config.ManualTLS)),
},
{
name: "PeerAutoTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
config: config.NewClusterConfig(3, config.WithPeerTLS(config.AutoTLS)),
},
{
name: "ClientTLS",
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS},
config: config.NewClusterConfig(1, config.WithClientTLS(config.ManualTLS)),
},
{
name: "ClientAutoTLS",
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS},
config: config.NewClusterConfig(1, config.WithClientTLS(config.AutoTLS)),
},
}

Expand Down
4 changes: 2 additions & 2 deletions tests/common/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestMemberAdd(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
c := clusterTc.config
c.DisableStrictReconfigCheck = !quorumTc.strictReconfigCheck
c.StrictReconfigCheck = quorumTc.strictReconfigCheck
clus := testRunner.NewCluster(ctx, t, c)
defer clus.Close()
cc := framework.MustClient(clus.Client())
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestMemberRemove(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
c := clusterTc.config
c.DisableStrictReconfigCheck = !quorumTc.strictReconfigCheck
c.StrictReconfigCheck = quorumTc.strictReconfigCheck
clus := testRunner.NewCluster(ctx, t, c)
defer clus.Close()
// client connects to a specific member which won't be removed from cluster
Expand Down
8 changes: 4 additions & 4 deletions tests/common/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ClusterConfig{ClusterSize: 1})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(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.ClusterConfig{ClusterSize: 1})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(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.ClusterConfig{ClusterSize: 1})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(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.ClusterConfig{ClusterSize: 1})
clus := testRunner.NewCluster(ctx, t, config.NewClusterConfig(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
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 @@ -45,11 +45,11 @@ func TestWaitLeader_MemberStop(t *testing.T) {
tcs := []testCase{
{
name: "PeerTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
config: config.NewClusterConfig(3, config.WithPeerTLS(config.ManualTLS)),
},
{
name: "PeerAutoTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
config: config.NewClusterConfig(3, config.WithPeerTLS(config.AutoTLS)),
},
}

Expand Down
49 changes: 42 additions & 7 deletions tests/framework/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,46 @@ const (
)

type ClusterConfig struct {
ClusterSize int
PeerTLS TLSConfig
ClientTLS TLSConfig
QuotaBackendBytes int64
DisableStrictReconfigCheck bool
AuthToken string
SnapshotCount int
ClusterSize int
PeerTLS TLSConfig
ClientTLS TLSConfig
QuotaBackendBytes int64
StrictReconfigCheck bool
AuthToken string
SnapshotCount int
}

func defaultClusterConfig() ClusterConfig {
return ClusterConfig{StrictReconfigCheck: true}
}

func NewClusterConfig(clusterSize int, opts ...ClusterOption) ClusterConfig {
c := defaultClusterConfig()
c.ClusterSize = clusterSize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: can we add a ClusterOption interface for ClusterSize as well? The benefit is that we don't need to provide a clusterSize if we use the default value.

It isn't a big deal. Feel free to think/discuss this in a separate PR.

for _, opt := range opts {
opt(&c)
}
return c
}

type ClusterOption func(*ClusterConfig)

func WithPeerTLS(tls TLSConfig) ClusterOption {
return func(c *ClusterConfig) { c.PeerTLS = tls }
}

func WithClientTLS(tls TLSConfig) ClusterOption {
return func(c *ClusterConfig) { c.ClientTLS = tls }
}

func WithQuotaBackendBytes(bytes int64) ClusterOption {
return func(c *ClusterConfig) { c.QuotaBackendBytes = bytes }
}

func WithSnapshotCount(count int) ClusterOption {
return func(c *ClusterConfig) { c.SnapshotCount = count }
}

func WithDisableStrictReconfigCheck() ClusterOption {
return func(c *ClusterConfig) { c.StrictReconfigCheck = false }
}
2 changes: 1 addition & 1 deletion tests/framework/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, cfg config.Clus
InitialToken: "new",
ClusterSize: cfg.ClusterSize,
QuotaBackendBytes: cfg.QuotaBackendBytes,
DisableStrictReconfigCheck: cfg.DisableStrictReconfigCheck,
DisableStrictReconfigCheck: !cfg.StrictReconfigCheck,
AuthTokenOpts: cfg.AuthToken,
SnapshotCount: cfg.SnapshotCount,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, cfg con
integrationCfg := integration.ClusterConfig{
Size: cfg.ClusterSize,
QuotaBackendBytes: cfg.QuotaBackendBytes,
DisableStrictReconfigCheck: cfg.DisableStrictReconfigCheck,
DisableStrictReconfigCheck: !cfg.StrictReconfigCheck,
AuthToken: cfg.AuthToken,
SnapshotCount: uint64(cfg.SnapshotCount),
}
Expand Down