From e4f239408cf8d7128df6140ff5b8149bd8dd6b0d Mon Sep 17 00:00:00 2001 From: Geeta Gharpure Date: Fri, 18 Aug 2023 16:14:35 +0000 Subject: [PATCH] Update test for v2 deprecation to verify membership match Signed-off-by: Geeta Gharpure --- tests/e2e/v2store_deprecation_test.go | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 432a61b2a84..bf94c58ba14 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -18,15 +18,19 @@ import ( "bytes" "context" "fmt" + "reflect" "sort" "strings" "testing" + "github.com/coreos/go-semver/semver" "github.com/stretchr/testify/assert" + "go.uber.org/zap" "go.uber.org/zap/zaptest" "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/server/v3/etcdserver" + "go.etcd.io/etcd/server/v3/etcdserver/api/membership" "go.etcd.io/etcd/server/v3/etcdserver/api/snap" "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" "go.etcd.io/etcd/tests/v3/framework/config" @@ -125,15 +129,12 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) { assert.NoError(t, epc.Close()) assertSnapshotsMatch(t, oldMemberDataDir, newMemberDataDir, func(data []byte) []byte { - // Patch cluster version - data = bytes.Replace(data, []byte("3.5.0"), []byte("X.X.X"), -1) - data = bytes.Replace(data, []byte("3.6.0"), []byte("X.X.X"), -1) // Patch members ids for i, mid := range members1 { - data = bytes.Replace(data, []byte(fmt.Sprintf("%x", mid)), []byte(fmt.Sprintf("member%d", i+1)), -1) + data = bytes.Replace(data, []byte(fmt.Sprintf("%x", mid)), []byte(fmt.Sprintf("%d", i+1)), -1) } for i, mid := range members2 { - data = bytes.Replace(data, []byte(fmt.Sprintf("%x", mid)), []byte(fmt.Sprintf("member%d", i+1)), -1) + data = bytes.Replace(data, []byte(fmt.Sprintf("%x", mid)), []byte(fmt.Sprintf("%d", i+1)), -1) } return data }) @@ -250,7 +251,23 @@ func assertSnapshotsMatch(t testing.TB, firstDataDir, secondDataDir string, patc if err != nil { t.Fatal(err) } - assert.Equal(t, openSnap(patch(firstSnapshot.Data)), openSnap(patch(secondSnapshot.Data))) + assertMembershipEqual(t, openSnap(patch(firstSnapshot.Data)), openSnap(patch(secondSnapshot.Data))) + } +} + +func assertMembershipEqual(t testing.TB, firstStore v2store.Store, secondStore v2store.Store) { + rc1 := membership.NewCluster(zaptest.NewLogger(t)) + rc1.SetStore(firstStore) + rc1.Recover(func(lg *zap.Logger, v *semver.Version) { return }) + + rc2 := membership.NewCluster(zaptest.NewLogger(t)) + rc2.SetStore(secondStore) + rc2.Recover(func(lg *zap.Logger, v *semver.Version) { return }) + + //membership should match + if g := rc1.Members(); !reflect.DeepEqual(g, rc2.Members()) { + t.Logf("memberids_from_last_version = %+v, member_ids_from_current_version = %+v", rc1.MemberIDs(), rc2.MemberIDs()) + t.Errorf("members_from_last_version_snapshot = %+v, members_from_current_version_snapshot %+v", rc1.Members(), rc2.Members()) } }