Skip to content

Commit

Permalink
Merge pull request #16441 from geetasg/pr8
Browse files Browse the repository at this point in the history
Update test for v2 deprecation to verify membership match
  • Loading branch information
serathius authored Aug 21, 2023
2 parents 0a3ec01 + e4f2394 commit 3371f26
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 3371f26

Please sign in to comment.