Skip to content

Commit 2979e21

Browse files
authored
test: enhance testing with data assertion scripts (#1209)
* test: enhance Redis cluster testing with data assertion scripts - Added new steps in the e2e test for Redis cluster to apply a data assertion tool, `data-assert`, for generating and validating data in the Redis cluster. - Replaced the previous Redis GET/SET checks with a more comprehensive data generation and validation process using the `data-assert` tool. - Introduced additional assertions to ensure data consistency after scaling operations. This update improves the reliability of e2e tests by ensuring data integrity in Redis clusters. Signed-off-by: drivebyer <wuyangmuc@gmail.com> * path Signed-off-by: drivebyer <wuyangmuc@gmail.com> * password Signed-off-by: drivebyer <wuyangmuc@gmail.com> * password Signed-off-by: drivebyer <wuyangmuc@gmail.com> * password Signed-off-by: drivebyer <wuyangmuc@gmail.com> * ha Signed-off-by: drivebyer <wuyangmuc@gmail.com> * update Signed-off-by: drivebyer <wuyangmuc@gmail.com> * fix Signed-off-by: drivebyer <wuyangmuc@gmail.com> --------- Signed-off-by: drivebyer <wuyangmuc@gmail.com>
1 parent bb4ed61 commit 2979e21

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

tests/data-assert/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func genRedisDataCmd(cmd *cobra.Command, args []string) {
8181
})
8282
case "sentinel":
8383
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
84-
MasterName: "mymaster",
84+
MasterName: "myMaster",
8585
SentinelAddrs: hosts,
8686
Password: pass,
8787
})
@@ -145,7 +145,7 @@ func checkRedisData() error {
145145
})
146146
case "sentinel":
147147
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
148-
MasterName: "mymaster",
148+
MasterName: "myMaster",
149149
SentinelAddrs: hosts,
150150
Password: pass,
151151
})

tests/data-assert/resources.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ data:
8888
})
8989
case "sentinel":
9090
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
91-
MasterName: "mymaster",
91+
MasterName: "myMaster",
9292
SentinelAddrs: hosts,
9393
Password: pass,
9494
})
@@ -152,7 +152,7 @@ data:
152152
})
153153
case "sentinel":
154154
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
155-
MasterName: "mymaster",
155+
MasterName: "myMaster",
156156
SentinelAddrs: hosts,
157157
Password: pass,
158158
})

tests/e2e-chainsaw/v1beta2/setup/ha/chainsaw-test.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ spec:
1515
- try:
1616
- apply:
1717
file: ha.yaml
18+
- apply:
19+
file: ../../../../data-assert/resources.yaml
1820

1921
- name: Test Master IP consistency
2022
try:
@@ -31,6 +33,16 @@ spec:
3133
check:
3234
(contains($stdout, 'OK')): true
3335

36+
- name: Put data
37+
try:
38+
- script:
39+
timeout: 30s
40+
content: >
41+
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
42+
bash -c "cd /go/src/data-assert && go run main.go gen-redis-data --host redis-sentinel-sentinel.${NAMESPACE}.svc.cluster.local:26379 --mode sentinel"
43+
check:
44+
(contains($stdout, 'OK')): true
45+
3446
# New created cluster, the first pod is master
3547
- name: Terminate the redis-replication-0 pod
3648
try:
@@ -53,3 +65,13 @@ spec:
5365
if [ "$MASTER_IP_FROM_SENTINEL" = "$MASTER_IP_FROM_LABEL" ] && [ "$MASTER_IP_FROM_SENTINEL" = "$MASTER_IP_FROM_STATUS" ]; then echo "OK"; else echo "FAIL"; fi
5466
check:
5567
(contains($stdout, 'OK')): true
68+
69+
- name: Assert data
70+
try:
71+
- script:
72+
timeout: 30s
73+
content: >
74+
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
75+
bash -c "cd /go/src/data-assert && go run main.go chk-redis-data --host redis-sentinel-sentinel.${NAMESPACE}.svc.cluster.local:26379 --mode sentinel"
76+
check:
77+
(contains($stdout, 'OK')): true

tests/e2e-chainsaw/v1beta2/setup/redis-cluster/chainsaw-test.yaml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ spec:
1111
file: cluster.yaml
1212
- apply:
1313
file: secret.yaml
14+
- apply:
15+
file: ../../../../data-assert/resources.yaml
1416
- assert:
1517
file: ready-cluster.yaml
1618
- assert:
@@ -22,22 +24,15 @@ spec:
2224
- assert:
2325
file: secret.yaml
2426

25-
- name: Check Redis GET/SET
27+
- name: Put data
2628
try:
2729
- script:
2830
timeout: 30s
2931
content: >
30-
kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 --
31-
redis-cli -c -p 6379 -a Opstree1234 set foo-0 bar-0
32+
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
33+
bash -c "cd /go/src/data-assert && go run main.go gen-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster --password Opstree1234"
3234
check:
3335
(contains($stdout, 'OK')): true
34-
- script:
35-
timeout: 30s
36-
content: >
37-
kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 --
38-
redis-cli -c -p 6379 -a Opstree1234 get foo-0
39-
check:
40-
(contains($stdout, 'bar-0')): true
4136

4237
- name: Scale Out Redis Cluster
4338
try:
@@ -64,13 +59,33 @@ spec:
6459
- assert:
6560
file: cluster-scale-out-status-03.yaml
6661

62+
- name: Assert data
63+
try:
64+
- script:
65+
timeout: 30s
66+
content: >
67+
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
68+
bash -c "cd /go/src/data-assert && go run main.go chk-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster --password Opstree1234"
69+
check:
70+
(contains($stdout, 'OK')): true
71+
6772
- name: Scale In Redis Cluster
6873
try:
6974
- apply:
7075
file: cluster.yaml
7176
- assert:
7277
file: ready-cluster.yaml
7378

79+
- name: Assert data
80+
try:
81+
- script:
82+
timeout: 30s
83+
content: >
84+
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
85+
bash -c "cd /go/src/data-assert && go run main.go chk-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster --password Opstree1234"
86+
check:
87+
(contains($stdout, 'OK')): true
88+
7489
- name: redis-cluster-uninstall
7590
try:
7691
- delete:

0 commit comments

Comments
 (0)