Skip to content

Commit

Permalink
fix: TestV2DeprecationSnapshotMatches
Browse files Browse the repository at this point in the history
Signed-off-by: Clement <gh.2lgqz@aleeas.com>
  • Loading branch information
clement2026 committed Aug 31, 2024
1 parent 49c5a42 commit 3c14a8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
36 changes: 26 additions & 10 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 @@ -138,7 +139,30 @@ 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)
}

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 creates an additional raft log snapshot 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)
Expand Down Expand Up @@ -237,16 +261,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))
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/raft_log_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestRaftLogSnapshotExistsPostStartUp(t *testing.T) {
// NOTE: When starting a new cluster with 1 member, the member will
// apply 3 ConfChange directly at the beginning, setting the applied index to 4.
for i := 0; i < 102-4; i++ {
_, err := kvc.Put(context.TODO(), &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")})
_, err = kvc.Put(context.TODO(), &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")})
if err != nil {
t.Fatalf("#%d: couldn't put key (%v)", i, err)
}
Expand Down

0 comments on commit 3c14a8f

Please sign in to comment.