Skip to content

Commit

Permalink
tests: Extend common test to run previous release
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Nov 3, 2022
1 parent 0dfd726 commit 9ceec77
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 103 deletions.
47 changes: 47 additions & 0 deletions tests/common/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,60 @@
package common

import (
"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func init() {
testRunner = framework.E2eTestRunner
clusterTestCases = e2eClusterTestCases
}

func e2eClusterTestCases() []testCase {
tcs := []testCase{
{
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},
},
}
if fileutil.Exist(e2e.BinPath.EtcdLastRelease) {
tcs = append(tcs, testCase{
name: "MinorityLastVersion",
config: config.ClusterConfig{
ClusterSize: 3,
E2eConfig: &config.E2eClusterConfig{
Version: config.MinorityLastVersion,
},
},
}, testCase{
name: "QuorumLastVersion",
config: config.ClusterConfig{
ClusterSize: 3,
E2eConfig: &config.E2eClusterConfig{
Version: config.QuorumLastVersion,
},
},
})
}
return tcs
}

func WithAuth(userName, password string) config.ClientOption {
Expand Down
26 changes: 26 additions & 0 deletions tests/common/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ import (

func init() {
testRunner = framework.IntegrationTestRunner
clusterTestCases = integrationClusterTestCases
}

func integrationClusterTestCases() []testCase {
return []testCase{
{
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},
},
}
}

func WithAuth(userName, password string) config.ClientOption {
Expand Down
6 changes: 3 additions & 3 deletions tests/common/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

func TestKVPut(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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 Expand Up @@ -62,7 +62,7 @@ func TestKVPut(t *testing.T) {

func TestKVGet(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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 Expand Up @@ -122,7 +122,7 @@ func TestKVGet(t *testing.T) {

func TestKVDelete(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
for _, tc := range clusterTestCases() {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
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 @@ -29,7 +29,7 @@ import (
func TestLeaseGrantTimeToLive(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
for _, tc := range clusterTestCases() {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand All @@ -53,7 +53,7 @@ func TestLeaseGrantTimeToLive(t *testing.T) {
func TestLeaseGrantAndList(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
for _, tc := range clusterTestCases() {
nestedCases := []struct {
name string
leaseCount int
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestLeaseGrantAndList(t *testing.T) {
func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
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 Expand Up @@ -157,7 +157,7 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
func TestLeaseGrantKeepAliveOnce(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
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 Expand Up @@ -186,7 +186,7 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
func TestLeaseGrantRevoke(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
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
26 changes: 2 additions & 24 deletions tests/common/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,8 @@ import (
"go.etcd.io/etcd/tests/v3/framework/config"
)

var testRunner framework.TestRunner

var clusterTestCases = []testCase{
{
name: "NoTLS",
config: config.NewClusterConfig(config.WithClusterSize(1)),
},
{
name: "PeerTLS",
config: config.NewClusterConfig(config.WithPeerTLS(config.ManualTLS)),
},
{
name: "PeerAutoTLS",
config: config.NewClusterConfig(config.WithPeerTLS(config.AutoTLS)),
},
{
name: "ClientTLS",
config: config.NewClusterConfig(config.WithClusterSize(1), config.WithClientTLS(config.ManualTLS)),
},
{
name: "ClientAutoTLS",
config: config.NewClusterConfig(config.WithClusterSize(1), config.WithClientTLS(config.AutoTLS)),
},
}
var testRunner = framework.UnitTestRunner
var clusterTestCases = func() []testCase { return nil }

func TestMain(m *testing.M) {
testRunner.TestMain(m)
Expand Down
6 changes: 3 additions & 3 deletions tests/common/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func TestMemberList(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
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 Expand Up @@ -102,7 +102,7 @@ func TestMemberAdd(t *testing.T) {

for _, learnerTc := range learnerTcs {
for _, quorumTc := range quorumTcs {
for _, clusterTc := range clusterTestCases {
for _, clusterTc := range clusterTestCases() {
t.Run(learnerTc.name+"/"+quorumTc.name+"/"+clusterTc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestMemberRemove(t *testing.T) {
}

for _, quorumTc := range tcs {
for _, clusterTc := range clusterTestCases {
for _, clusterTc := range clusterTestCases() {
if !quorumTc.strictReconfigCheck && clusterTc.config.ClusterSize == 1 {
// skip these test cases
// when strictReconfigCheck is disabled, calling MemberRemove will cause the single node to panic
Expand Down
2 changes: 1 addition & 1 deletion tests/common/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func TestRoleAdd_Simple(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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
2 changes: 1 addition & 1 deletion tests/common/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestStatus(t *testing.T) {

testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
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
4 changes: 2 additions & 2 deletions tests/common/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestTxnSucc(t *testing.T) {
results: []string{"SUCCESS", `key "with" space`, "value \x23"},
},
}
for _, cfg := range clusterTestCases {
for _, cfg := range clusterTestCases() {
t.Run(cfg.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestTxnFail(t *testing.T) {
results: []string{"FAILURE", "OK"},
},
}
for _, cfg := range clusterTestCases {
for _, cfg := range clusterTestCases() {
t.Run(cfg.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/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestUserAdd_Simple(t *testing.T) {
password: "bar",
},
}
for _, tc := range clusterTestCases {
for _, tc := range clusterTestCases() {
for _, nc := range tcs {
t.Run(tc.name+"/"+nc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestUserAdd_Simple(t *testing.T) {

func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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 Expand Up @@ -126,7 +126,7 @@ func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) {

func TestUserList(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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 Expand Up @@ -167,7 +167,7 @@ func TestUserList(t *testing.T) {

func TestUserDelete(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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 Expand Up @@ -219,7 +219,7 @@ func TestUserDelete(t *testing.T) {

func TestUserChangePassword(t *testing.T) {
testRunner.BeforeTest(t)
for _, tc := range clusterTestCases {
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
2 changes: 1 addition & 1 deletion tests/common/wait_leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func TestWaitLeader(t *testing.T) {
testRunner.BeforeTest(t)

for _, tc := range clusterTestCases {
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
2 changes: 1 addition & 1 deletion tests/common/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestWatch(t *testing.T) {
testRunner.BeforeTest(t)
watchTimeout := 1 * time.Second
for _, tc := range clusterTestCases {
for _, tc := range clusterTestCases() {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) {
e2e.BeforeTest(t)

t.Logf("Create cluster with version %s", currentVersionStr)
epc := newCluster(t, currentEtcdBinary, clusterSize)
epc := newCluster(t, clusterSize)
for i := 0; i < len(epc.Procs); i++ {
validateVersion(t, epc.Cfg, epc.Procs[i], version.Versions{
Cluster: currentVersionStr,
Expand Down Expand Up @@ -119,9 +119,8 @@ func testDowngradeUpgrade(t *testing.T, clusterSize int) {
t.Log("Upgrade complete")
}

func newCluster(t *testing.T, execPath string, clusterSize int) *e2e.EtcdProcessCluster {
func newCluster(t *testing.T, clusterSize int) *e2e.EtcdProcessCluster {
epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{
ExecPath: execPath,
ClusterSize: clusterSize,
InitialToken: "new",
KeepDataDir: true,
Expand Down
6 changes: 0 additions & 6 deletions tests/e2e/ctl_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/api/v3/version"
"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/pkg/v3/flags"
"go.etcd.io/etcd/tests/v3/framework/e2e"
Expand All @@ -51,13 +50,8 @@ func TestClusterVersion(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
binary := e2e.BinPath.Etcd
if !fileutil.Exist(binary) {
t.Skipf("%q does not exist", binary)
}
e2e.BeforeTest(t)
cfg := e2e.NewConfigNoTLS()
cfg.ExecPath = binary
cfg.SnapshotCount = 3
cfg.BaseScheme = "unix" // to avoid port conflict
cfg.RollingStart = tt.rollingStart
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/v2"
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
"go.etcd.io/etcd/tests/v3/framework/integration"
)
Expand All @@ -38,14 +39,13 @@ func TestTLSClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t
func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
e2e.BeforeTest(t)

lastReleaseBinary := e2e.BinPath.EtcdLastRelease
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) {
t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease)
}

dc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, &e2e.EtcdProcessClusterConfig{
BasePort: 2000,
ExecPath: lastReleaseBinary,
Version: config.LastVersion,
ClusterSize: 1,
EnableV2: true,
})
Expand Down
Loading

0 comments on commit 9ceec77

Please sign in to comment.