Skip to content

Commit 37eaafa

Browse files
authored
Merge pull request #19680 from henrybear327/issue/18386_end_of_test_check_case_1
[Robustness Test] Add HashKV check to robustness test
2 parents 839985d + a203755 commit 37eaafa

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

tests/robustness/client/kvhash.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2025 The etcd Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package client
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"time"
21+
22+
"go.uber.org/zap"
23+
24+
clientv3 "go.etcd.io/etcd/client/v3"
25+
"go.etcd.io/etcd/tests/v3/framework/e2e"
26+
)
27+
28+
func CheckHashKV(ctx context.Context, clus *e2e.EtcdProcessCluster) error {
29+
c, err := clientv3.New(clientv3.Config{
30+
Endpoints: clus.EndpointsGRPC(),
31+
Logger: zap.NewNop(),
32+
DialKeepAliveTime: 10 * time.Second,
33+
DialKeepAliveTimeout: 100 * time.Millisecond,
34+
})
35+
if err != nil {
36+
return err
37+
}
38+
defer c.Close()
39+
40+
hashKV, err := c.HashKV(ctx, clus.EndpointsGRPC()[0], 0)
41+
if err != nil {
42+
return err
43+
}
44+
rev := hashKV.Header.Revision
45+
46+
hashKVs := make([]*clientv3.HashKVResponse, 0)
47+
hashKVs = append(hashKVs, hashKV)
48+
49+
for _, member := range clus.Procs {
50+
hashKV, err := c.HashKV(ctx, member.EndpointsGRPC()[0], rev)
51+
if err != nil {
52+
return err
53+
}
54+
if hashKV.Header.Revision != rev {
55+
return fmt.Errorf("max revision between nodes should be the same. Want %v, get %v", rev, hashKV.Header.Revision)
56+
}
57+
hashKVs = append(hashKVs, hashKV)
58+
}
59+
60+
for i := 1; i < len(hashKVs); i++ {
61+
if hashKVs[i-1].HashRevision != hashKVs[i].HashRevision {
62+
return fmt.Errorf("hashRevision mismatch, node %v has %+v, node %v has %+v", hashKVs[i-1].Header.MemberId, hashKVs[i-1], hashKVs[i].Header.MemberId, hashKVs[i])
63+
}
64+
if hashKVs[i-1].CompactRevision != hashKVs[i].CompactRevision {
65+
return fmt.Errorf("compactRevision mismatch, node %v has %+v, node %v has %+v", hashKVs[i-1].Header.MemberId, hashKVs[i-1], hashKVs[i].Header.MemberId, hashKVs[i])
66+
}
67+
if hashKVs[i-1].Hash != hashKVs[i].Hash {
68+
return fmt.Errorf("hash mismatch, node %v has %+v, node %v has %+v", hashKVs[i-1].Header.MemberId, hashKVs[i-1], hashKVs[i].Header.MemberId, hashKVs[i])
69+
}
70+
}
71+
return nil
72+
}

tests/robustness/main_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func runScenario(ctx context.Context, t *testing.T, s scenarios.TestScenario, lg
149149
return nil
150150
})
151151
g.Wait()
152+
153+
err := client.CheckHashKV(ctx, clus)
154+
if err != nil {
155+
t.Error(err)
156+
}
152157
return append(operationReport, append(failpointClientReport, watchReport...)...)
153158
}
154159

0 commit comments

Comments
 (0)