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

tests: fix TestV2DeprecationSnapshotMatches #18583

Closed
Closed
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
36 changes: 25 additions & 11 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
Loading