Skip to content

Commit

Permalink
Update unit test to verify WAL versions
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Jan 27, 2025
1 parent d741e69 commit 7b4b96d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/storage/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ func TestMigrate(t *testing.T) {
},
expectVersion: nil,
},
/* TODO: add a dedicated request for testing only to cover such case
{
name: "Downgrading v3.6 to v3.5 works even if there is ClusterVersionSetRequest WAL entries with 3.6 clusterVersion",
name: "Downgrading v3.6 to v3.5 fails if there are newer WAL entries",
version: version.V3_6,
targetVersion: version.V3_5,
walEntries: []etcdserverpb.InternalRaftRequest{
{ClusterVersionSet: &membershippb.ClusterVersionSetRequest{Ver: "3.6.0"}},
{DowngradeVersionTest: &etcdserverpb.DowngradeVersionTestRequest{Ver: "3.6.0"}},
},
expectVersion: nil, // 3.5 doesn't have field `storageVersion`, so it should be nil.
expectError: false,
},*/
expectVersion: &version.V3_6,
expectError: true,
expectErrorMsg: "cannot downgrade storage, WAL contains newer entries",
},
{
name: "Downgrading v3.5 to v3.4 is not supported as schema was introduced in v3.6",
version: version.V3_5,
Expand Down
26 changes: 26 additions & 0 deletions server/storage/wal/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestEtcdVersionFromEntry(t *testing.T) {
raftReq := etcdserverpb.InternalRaftRequest{Header: &etcdserverpb.RequestHeader{AuthRevision: 1}}
normalRequestData := pbutil.MustMarshal(&raftReq)

downgradeVersionTestV3_6Req := etcdserverpb.InternalRaftRequest{DowngradeVersionTest: &etcdserverpb.DowngradeVersionTestRequest{Ver: "3.6.0"}}
downgradeVersionTestV3_6Data := pbutil.MustMarshal(&downgradeVersionTestV3_6Req)

downgradeVersionTestV3_7Req := etcdserverpb.InternalRaftRequest{DowngradeVersionTest: &etcdserverpb.DowngradeVersionTestRequest{Ver: "3.7.0"}}
downgradeVersionTestV3_7Data := pbutil.MustMarshal(&downgradeVersionTestV3_7Req)

confChange := raftpb.ConfChange{Type: raftpb.ConfChangeAddLearnerNode}
confChangeData := pbutil.MustMarshal(&confChange)

Expand All @@ -56,6 +62,26 @@ func TestEtcdVersionFromEntry(t *testing.T) {
},
expect: &version.V3_1,
},
{
name: "Setting downgradeTest version to 3.6 implies version within WAL",
input: raftpb.Entry{
Term: 1,
Index: 2,
Type: raftpb.EntryNormal,
Data: downgradeVersionTestV3_6Data,
},
expect: &version.V3_6,
},
{
name: "Setting downgradeTest version to 3.7 implies version within WAL",
input: raftpb.Entry{
Term: 1,
Index: 2,
Type: raftpb.EntryNormal,
Data: downgradeVersionTestV3_7Data,
},
expect: &version.V3_7,
},
{
name: "Using ConfigChange implies v3.0",
input: raftpb.Entry{
Expand Down

0 comments on commit 7b4b96d

Please sign in to comment.