Skip to content

Commit

Permalink
test: enhance testing with data assertion scripts (#1209)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* path

Signed-off-by: drivebyer <[email protected]>

* password

Signed-off-by: drivebyer <[email protected]>

* password

Signed-off-by: drivebyer <[email protected]>

* password

Signed-off-by: drivebyer <[email protected]>

* ha

Signed-off-by: drivebyer <[email protected]>

* update

Signed-off-by: drivebyer <[email protected]>

* fix

Signed-off-by: drivebyer <[email protected]>

---------

Signed-off-by: drivebyer <[email protected]>
  • Loading branch information
drivebyer authored Jan 16, 2025
1 parent bb4ed61 commit 2979e21
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/data-assert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func genRedisDataCmd(cmd *cobra.Command, args []string) {
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
MasterName: "myMaster",
SentinelAddrs: hosts,
Password: pass,
})
Expand Down Expand Up @@ -145,7 +145,7 @@ func checkRedisData() error {
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
MasterName: "myMaster",
SentinelAddrs: hosts,
Password: pass,
})
Expand Down
4 changes: 2 additions & 2 deletions tests/data-assert/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ data:
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
MasterName: "myMaster",
SentinelAddrs: hosts,
Password: pass,
})
Expand Down Expand Up @@ -152,7 +152,7 @@ data:
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
MasterName: "myMaster",
SentinelAddrs: hosts,
Password: pass,
})
Expand Down
22 changes: 22 additions & 0 deletions tests/e2e-chainsaw/v1beta2/setup/ha/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ spec:
- try:
- apply:
file: ha.yaml
- apply:
file: ../../../../data-assert/resources.yaml

- name: Test Master IP consistency
try:
Expand All @@ -31,6 +33,16 @@ spec:
check:
(contains($stdout, 'OK')): true

- name: Put data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
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"
check:
(contains($stdout, 'OK')): true

# New created cluster, the first pod is master
- name: Terminate the redis-replication-0 pod
try:
Expand All @@ -53,3 +65,13 @@ spec:
if [ "$MASTER_IP_FROM_SENTINEL" = "$MASTER_IP_FROM_LABEL" ] && [ "$MASTER_IP_FROM_SENTINEL" = "$MASTER_IP_FROM_STATUS" ]; then echo "OK"; else echo "FAIL"; fi
check:
(contains($stdout, 'OK')): true

- name: Assert data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
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"
check:
(contains($stdout, 'OK')): true
35 changes: 25 additions & 10 deletions tests/e2e-chainsaw/v1beta2/setup/redis-cluster/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spec:
file: cluster.yaml
- apply:
file: secret.yaml
- apply:
file: ../../../../data-assert/resources.yaml
- assert:
file: ready-cluster.yaml
- assert:
Expand All @@ -22,22 +24,15 @@ spec:
- assert:
file: secret.yaml

- name: Check Redis GET/SET
- name: Put data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 --
redis-cli -c -p 6379 -a Opstree1234 set foo-0 bar-0
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
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"
check:
(contains($stdout, 'OK')): true
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 --
redis-cli -c -p 6379 -a Opstree1234 get foo-0
check:
(contains($stdout, 'bar-0')): true

- name: Scale Out Redis Cluster
try:
Expand All @@ -64,13 +59,33 @@ spec:
- assert:
file: cluster-scale-out-status-03.yaml

- name: Assert data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
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"
check:
(contains($stdout, 'OK')): true

- name: Scale In Redis Cluster
try:
- apply:
file: cluster.yaml
- assert:
file: ready-cluster.yaml

- name: Assert data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
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"
check:
(contains($stdout, 'OK')): true

- name: redis-cluster-uninstall
try:
- delete:
Expand Down

0 comments on commit 2979e21

Please sign in to comment.