test: enhance case TestEndpointHashKV to check both hash and hashRevision
@@ -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"
)
@@ -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) {
