Skip to content

Commit

Permalink
test: enhance case TestEndpointHashKV to check both hash and hashRevi…
Browse files Browse the repository at this point in the history
…sion

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Nov 21, 2022
1 parent 10bceba commit b239362
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions tests/common/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ package common

import (
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

Expand All @@ -44,12 +47,30 @@ func TestEndpointHashKV(t *testing.T) {
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.HashKV(ctx, 0)
if err != nil {
t.Fatalf("get endpoint hashkv error: %v", err)

t.Log("Add some entries")
for i := 0; i < 10; i++ {
key := fmt.Sprintf("key-%d", i)
value := fmt.Sprintf("value-%d", i)
if err := cc.Put(ctx, key, value, config.PutOptions{}); err != nil {
t.Fatalf("count not put key %q, err: %s", key, err)
}
})
}

t.Log("Check all members' Hash and HashRevision")
require.Eventually(t, func() bool {
resp, err := cc.HashKV(ctx, 0)
require.NoError(t, err, "failed to get endpoint hashkv: %v", err)

require.Equal(t, 3, len(resp))
if resp[0].HashRevision == resp[1].HashRevision && resp[0].HashRevision == resp[2].HashRevision {
require.Equal(t, resp[0].Hash, resp[1].Hash)
require.Equal(t, resp[0].Hash, resp[2].Hash)
return true
}
t.Logf("HashRevisions are not equal: [%d, %d, %d], retry...", resp[0].HashRevision, resp[1].HashRevision, resp[2].HashRevision)
return false
}, 5*time.Second, 200*time.Millisecond)
}

func TestEndpointHealth(t *testing.T) {
Expand Down

0 comments on commit b239362

Please sign in to comment.