Skip to content

Commit

Permalink
tests/e2e: add cases for watcher on compacted revision when it's mix …
Browse files Browse the repository at this point in the history
…version

Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Jul 9, 2024
1 parent 7e70357 commit c19beea
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/e2e/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/mvccpb"
v3rpc "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/pkg/v3/fileutil"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
Expand Down Expand Up @@ -390,6 +391,94 @@ func TestVerifyHashKVAfterCompact(t *testing.T) {
}
}

func TestVerifyHashKVAfterCompactMixVersion(t *testing.T) {
if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) {
t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease)
}

tests := []struct {
compactedOnTombstoneRev bool
hashKVOnCompactedRev bool
consistentHash bool
}{
// The test performs compaction on tombstone revision.
// The tombstone revision is always larger than last compacted revision.
// So, both versions take the same hash value in compaction.
{
compactedOnTombstoneRev: true,
hashKVOnCompactedRev: true,
consistentHash: true,
},
// The test performs compaction on tombstone revision.
// For v3.5 version, the tombstone revision has been deleted so that that revision won't be included in new hash value.
// For main branch, even if the tombstone revision still exists,
// the tombstone revision is smaller that last compacted revision and the index.Keep(hashOnRev) won't keep it.
// So, main branch won't include the tombstone revision in new hash value as well.
// Both versions take the same hash value from HashKV.
{
compactedOnTombstoneRev: true,
hashKVOnCompactedRev: false,
consistentHash: true,
},
// FIXME(fuweid):
//
// The test performs HashKV on tombstone revision.
// For v3.5 version, the index.Keep(tombstoneRev) returns empty.
// So, the last compacted revision will be included in new hash value again.
//
// However, for the main branch, the index.Keep(tombstoneRev) returns one revision.
// So, the last compacted revision won't be included in new hash value.
// It caused inconsistent hash value.
{
compactedOnTombstoneRev: false,
hashKVOnCompactedRev: true,
consistentHash: false,
},
// The test performs HashKV on non-tombstone revision.
// The index.Keep(non-tombstone-revision) always returns non-empty result.
// Both versions won't include last compacted revision in new revision.
{
compactedOnTombstoneRev: false,
hashKVOnCompactedRev: false,
consistentHash: true,
},
}

for idx, tt := range tests {
t.Run(fmt.Sprintf("#%d", idx), func(t *testing.T) {
verifyHashKVAfterCompactFn(t, e2e.QuorumLastVersion, func(t *testing.T, cli *e2e.EtcdctlV3, lastRevision int64, tombstoneRevisions []int64) {
ctx := context.Background()

hashKVOnCompactedRev := lastRevision
if tt.hashKVOnCompactedRev {
hashKVOnCompactedRev = tombstoneRevisions[len(tombstoneRevisions)-1]
}

compactedOnRev := tombstoneRevisions[len(tombstoneRevisions)-1]
if !tt.compactedOnTombstoneRev {
compactedOnRev = hashKVOnCompactedRev - 8
}

t.Logf("COMPACT rev=%d", compactedOnRev)
_, err := cli.Compact(ctx, compactedOnRev, config.CompactOption{Physical: true})
require.NoError(t, err)

t.Logf("HashKV on rev=%d", hashKVOnCompactedRev)
resp, err := cli.HashKV(ctx, hashKVOnCompactedRev)
require.NoError(t, err)

require.Len(t, resp, 3)
require.True(t, resp[0].Hash != 0)
t.Logf("One Hash value is %d", resp[0].Hash)

require.Equal(t, tt.consistentHash, resp[0].Hash == resp[1].Hash && resp[1].Hash == resp[2].Hash,
"Expected consistentHash = %v, but got %d - %d - %d",
tt.consistentHash, resp[0].Hash, resp[1].Hash, resp[2].Hash)
})
})
}
}

// verifyHashKVAfterCompactFn will generate 3 tombstones on key foo.
func verifyHashKVAfterCompactFn(
t *testing.T,
Expand Down

0 comments on commit c19beea

Please sign in to comment.