From 6b2b77736d405757d5c42c7d71c6f5703635de4a Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 13 Sep 2024 08:13:48 +0800 Subject: [PATCH 1/4] fix: TestV2DeprecationSnapshotMatches Signed-off-by: Clement --- tests/e2e/v2store_deprecation_test.go | 41 +++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 99628cd54e3..dc3c0c6569f 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -28,6 +28,7 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zaptest" + "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/server/v3/etcdserver" @@ -138,7 +139,33 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) { members2 := addAndRemoveKeysAndMembers(ctx, t, cc2, snapshotCount) assert.NoError(t, epc.Close()) - assertSnapshotsMatch(t, oldMemberDataDir, newMemberDataDir, func(data []byte) []byte { + lastVer, err := e2e.GetVersionFromBinary(e2e.BinPath.EtcdLastRelease) + if err != nil { + t.Fatal(err) + } + currVer, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) + if err != nil { + t.Fatal(err) + } + + firstFiles, err := fileutil.ListFiles(oldMemberDataDir, filterSnapshotFiles) + if err != nil { + t.Fatal(err) + } + secondFiles, err := fileutil.ListFiles(newMemberDataDir, filterSnapshotFiles) + if err != nil { + t.Fatal(err) + } + assert.NotEmpty(t, firstFiles) + assert.NotEmpty(t, secondFiles) + + // v3.6 creates a raft log snapshot on server startup, but v3.5 doesn't + if lastVer.LessThan(version.V3_6) && (version.V3_6.Equal(*currVer) || version.V3_6.LessThan(*currVer)) { + assert.Equal(t, len(firstFiles)+1, len(secondFiles), "etcd v3.6 should create a snapshot of raft log on startup") + t.Skipf("raft log snapshots of %v are supposed to differ from of %v", currVer, lastVer) + } + + assertSnapshotsMatch(t, firstFiles, secondFiles, func(data []byte) []byte { // Patch members ids for i, mid := range members1 { data = bytes.Replace(data, []byte(fmt.Sprintf("%x", mid)), []byte(fmt.Sprintf("%d", i+1)), -1) @@ -237,18 +264,8 @@ func filterSnapshotFiles(path string) bool { return strings.HasSuffix(path, ".snap") } -func assertSnapshotsMatch(t testing.TB, firstDataDir, secondDataDir string, patch func([]byte) []byte) { +func assertSnapshotsMatch(t testing.TB, firstFiles, secondFiles []string, patch func([]byte) []byte) { lg := zaptest.NewLogger(t) - firstFiles, err := fileutil.ListFiles(firstDataDir, filterSnapshotFiles) - if err != nil { - t.Fatal(err) - } - secondFiles, err := fileutil.ListFiles(secondDataDir, filterSnapshotFiles) - if err != nil { - t.Fatal(err) - } - assert.NotEmpty(t, firstFiles) - assert.NotEmpty(t, secondFiles) assert.Equal(t, len(firstFiles), len(secondFiles)) sort.Strings(firstFiles) sort.Strings(secondFiles) From 7efb9b9fe4a899ca8f3df4f38c4d8978232ac4ab Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 13 Sep 2024 17:05:38 +0800 Subject: [PATCH 2/4] tests: fix TestV2DeprecationSnapshotMatches, maybe ignore the first snapshot file of etcd v3.6 Signed-off-by: Clement --- tests/e2e/v2store_deprecation_test.go | 64 +++++++++++++-------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index dc3c0c6569f..764c57954e4 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -139,33 +139,7 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) { members2 := addAndRemoveKeysAndMembers(ctx, t, cc2, snapshotCount) assert.NoError(t, epc.Close()) - lastVer, err := e2e.GetVersionFromBinary(e2e.BinPath.EtcdLastRelease) - if err != nil { - t.Fatal(err) - } - currVer, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) - if err != nil { - t.Fatal(err) - } - - firstFiles, err := fileutil.ListFiles(oldMemberDataDir, filterSnapshotFiles) - if err != nil { - t.Fatal(err) - } - secondFiles, err := fileutil.ListFiles(newMemberDataDir, filterSnapshotFiles) - if err != nil { - t.Fatal(err) - } - assert.NotEmpty(t, firstFiles) - assert.NotEmpty(t, secondFiles) - - // v3.6 creates a raft log snapshot on server startup, but v3.5 doesn't - if lastVer.LessThan(version.V3_6) && (version.V3_6.Equal(*currVer) || version.V3_6.LessThan(*currVer)) { - assert.Equal(t, len(firstFiles)+1, len(secondFiles), "etcd v3.6 should create a snapshot of raft log on startup") - t.Skipf("raft log snapshots of %v are supposed to differ from of %v", currVer, lastVer) - } - - assertSnapshotsMatch(t, firstFiles, secondFiles, func(data []byte) []byte { + assertSnapshotsMatch(t, oldMemberDataDir, newMemberDataDir, func(data []byte) []byte { // Patch members ids for i, mid := range members1 { data = bytes.Replace(data, []byte(fmt.Sprintf("%x", mid)), []byte(fmt.Sprintf("%d", i+1)), -1) @@ -264,17 +238,39 @@ func filterSnapshotFiles(path string) bool { return strings.HasSuffix(path, ".snap") } -func assertSnapshotsMatch(t testing.TB, firstFiles, secondFiles []string, patch func([]byte) []byte) { +func assertSnapshotsMatch(t testing.TB, oldMemberDataDir, newMemberDataDir string, patch func([]byte) []byte) { lg := zaptest.NewLogger(t) - assert.Equal(t, len(firstFiles), len(secondFiles)) - sort.Strings(firstFiles) - sort.Strings(secondFiles) - for i := 0; i < len(firstFiles); i++ { - firstSnapshot, err := snap.Read(lg, firstFiles[i]) + oldMemberSnapshots, err := fileutil.ListFiles(oldMemberDataDir, filterSnapshotFiles) + if err != nil { + t.Fatal(err) + } + newMemberSnapshots, err := fileutil.ListFiles(newMemberDataDir, filterSnapshotFiles) + if err != nil { + t.Fatal(err) + } + assert.NotEmpty(t, oldMemberSnapshots) + assert.NotEmpty(t, newMemberSnapshots) + + currVer, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) + if err != nil { + t.Fatal(err) + } + + // Starting from v3.6, etcd might create an extra snapshot file (appliedIndex == 1) on server startup. + // Except for this, other snapshot files should be the same as in old versions. + if (version.V3_6.Equal(*currVer) || version.V3_6.LessThan(*currVer)) && len(oldMemberSnapshots) < len(newMemberSnapshots) { + newMemberSnapshots = newMemberSnapshots[1:] + } + + assert.Equal(t, len(oldMemberSnapshots), len(newMemberSnapshots)) + sort.Strings(oldMemberSnapshots) + sort.Strings(newMemberSnapshots) + for i := 0; i < len(oldMemberSnapshots); i++ { + firstSnapshot, err := snap.Read(lg, oldMemberSnapshots[i]) if err != nil { t.Fatal(err) } - secondSnapshot, err := snap.Read(lg, secondFiles[i]) + secondSnapshot, err := snap.Read(lg, newMemberSnapshots[i]) if err != nil { t.Fatal(err) } From efd3ec6fa424708e8a552d42eaf6af39f5907ef0 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 13 Sep 2024 17:11:27 +0800 Subject: [PATCH 3/4] tests: fix TestV2DeprecationSnapshotMatches, maybe ignore the first snapshot file of etcd v3.6 Signed-off-by: Clement --- tests/e2e/v2store_deprecation_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 764c57954e4..f3e3be41483 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -251,6 +251,9 @@ func assertSnapshotsMatch(t testing.TB, oldMemberDataDir, newMemberDataDir strin assert.NotEmpty(t, oldMemberSnapshots) assert.NotEmpty(t, newMemberSnapshots) + sort.Strings(oldMemberSnapshots) + sort.Strings(newMemberSnapshots) + currVer, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) if err != nil { t.Fatal(err) @@ -259,12 +262,11 @@ func assertSnapshotsMatch(t testing.TB, oldMemberDataDir, newMemberDataDir strin // Starting from v3.6, etcd might create an extra snapshot file (appliedIndex == 1) on server startup. // Except for this, other snapshot files should be the same as in old versions. if (version.V3_6.Equal(*currVer) || version.V3_6.LessThan(*currVer)) && len(oldMemberSnapshots) < len(newMemberSnapshots) { + // Remove the extra snapshot file newMemberSnapshots = newMemberSnapshots[1:] } assert.Equal(t, len(oldMemberSnapshots), len(newMemberSnapshots)) - sort.Strings(oldMemberSnapshots) - sort.Strings(newMemberSnapshots) for i := 0; i < len(oldMemberSnapshots); i++ { firstSnapshot, err := snap.Read(lg, oldMemberSnapshots[i]) if err != nil { From d5f65e9f75556cdd5d1373af9b17284ae3bb105a Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 13 Sep 2024 17:41:42 +0800 Subject: [PATCH 4/4] retest Signed-off-by: Clement --- tests/e2e/v2store_deprecation_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index f3e3be41483..3654b7442ac 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -250,7 +250,6 @@ func assertSnapshotsMatch(t testing.TB, oldMemberDataDir, newMemberDataDir strin } assert.NotEmpty(t, oldMemberSnapshots) assert.NotEmpty(t, newMemberSnapshots) - sort.Strings(oldMemberSnapshots) sort.Strings(newMemberSnapshots)