Skip to content

Commit 7b1e4b1

Browse files
committed
feat redis: more robust redis cluster tests
1) use pytest\_userver.utils.sync.wait\*() 2) use async instead of blocking API where possible 3) reuse redis.asyncio.ConnectionPool for Redis client commit_hash:9aa4b5767d4b60a2a23b4e314817625c385c6e15
1 parent 1eac120 commit 7b1e4b1

File tree

3 files changed

+157
-148
lines changed

3 files changed

+157
-148
lines changed

redis/functional_tests/cluster_auto_topology/tests/test_redis_cluster.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import asyncio
2-
import logging
3-
import time
2+
3+
import pytest_userver.utils.sync as sync
44

55
KEYS_SEQ_LEN = 20 # enough sequential keys to test all slots
66
REDIS_PORT = 6379
77
FAILOVER_DEADLINE_SEC = 30 # maximum time allowed to finish failover
88

9-
logger = logging.getLogger(__name__)
10-
119

1210
async def test_happy_path(service_client, redis_cluster_topology):
1311
post_reqs = [
@@ -51,21 +49,17 @@ async def test_hard_failover(service_client, redis_cluster_topology):
5149

5250
# Start the failover
5351
redis_cluster_topology.get_masters()[0].stop()
54-
# wait until service detect that shard 0 is broken
55-
time.sleep(6)
5652

53+
# wait until service detect that shard 0 is broken
5754
# Failover starts in ~10 seconds
58-
for _ in range(FAILOVER_DEADLINE_SEC):
59-
write_ok = await _check_write_all_slots(
55+
async def is_ready():
56+
return await _check_write_all_slots(
6057
service_client,
6158
'hf_key2',
6259
'cde',
6360
)
64-
if not write_ok:
65-
await asyncio.sleep(1)
66-
continue
67-
break
68-
assert write_ok
61+
62+
await sync.wait(is_ready)
6963

7064
# Now that one of the replicas has become the master,
7165
# check reading from the remaining replica
@@ -80,18 +74,14 @@ async def test_add_shard(service_client, redis_cluster_topology):
8074
await redis_cluster_topology.add_shard()
8175

8276
# Failover starts in ~10 seconds
83-
for _ in range(FAILOVER_DEADLINE_SEC):
84-
write_ok = await _check_write_all_slots(
77+
async def is_ready():
78+
return await _check_write_all_slots(
8579
service_client,
8680
'hf_key2',
8781
'cde',
8882
)
89-
if not write_ok:
90-
await asyncio.sleep(1)
91-
continue
9283

93-
break
94-
assert write_ok
84+
await sync.wait(is_ready)
9585

9686
# Now that one of the replicas has become the master,
9787
# check reading from the remaining replica

redis/functional_tests/pytest_redis_cluster_topology_plugin/configs/cluster.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ cluster-enabled yes
1010

1111
save ""
1212

13+
loglevel debug
14+

0 commit comments

Comments
 (0)