diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 99628cd54e3..3654b7442ac 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" @@ -237,27 +238,40 @@ 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, oldMemberDataDir, newMemberDataDir string, patch func([]byte) []byte) { lg := zaptest.NewLogger(t) - firstFiles, err := fileutil.ListFiles(firstDataDir, filterSnapshotFiles) + oldMemberSnapshots, err := fileutil.ListFiles(oldMemberDataDir, filterSnapshotFiles) if err != nil { t.Fatal(err) } - secondFiles, err := fileutil.ListFiles(secondDataDir, filterSnapshotFiles) + newMemberSnapshots, err := fileutil.ListFiles(newMemberDataDir, 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) - for i := 0; i < len(firstFiles); i++ { - firstSnapshot, err := snap.Read(lg, firstFiles[i]) + 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) + } + + // 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)) + 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) }