Skip to content

Commit d5a8a1a

Browse files
author
shahar
committed
test(cluster): Test that cluster works with a standard cluster client.
In this case, `redis.RedisCluster`. To be double sure I also looked at the actual packets and saw that the client asks for `CLUSTER SLOTS`, and then after the redistribution of slots, following a few `MOVED` replied, it asks for the new slots again.
1 parent 981e2b2 commit d5a8a1a

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

tests/dragonfly/cluster_test.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,127 @@ async def test_cluster_slot_ownership_changes(df_local_factory):
284284
assert await c_nodes[0].execute_command("DBSIZE") == 1
285285
assert (await c_nodes[0].get("KEY0")).decode() == "value"
286286
assert await c_nodes[1].execute_command("DBSIZE") == 0
287+
288+
289+
@dfly_args({"proactor_threads": 4, "cluster_mode": "yes"})
290+
async def test_cluster_native_client(df_local_factory):
291+
# Start and configure cluster with 3 nodes
292+
nodes = [
293+
df_local_factory.create(port=BASE_PORT+i, admin_port=BASE_PORT+i+1000)
294+
for i in range(3)
295+
]
296+
df_local_factory.start_all(nodes)
297+
c_nodes = [aioredis.Redis(port=node.port) for node in nodes]
298+
c_nodes_admin = [aioredis.Redis(port=node.admin_port) for node in nodes]
299+
node_ids = await asyncio.gather(*(get_node_id(c) for c in c_nodes_admin))
300+
301+
config = f"""
302+
[
303+
{{
304+
"slot_ranges": [
305+
{{
306+
"start": 0,
307+
"end": 5000
308+
}}
309+
],
310+
"master": {{
311+
"id": "{node_ids[0]}",
312+
"ip": "localhost",
313+
"port": {nodes[0].port}
314+
}},
315+
"replicas": []
316+
}},
317+
{{
318+
"slot_ranges": [
319+
{{
320+
"start": 5001,
321+
"end": 10000
322+
}}
323+
],
324+
"master": {{
325+
"id": "{node_ids[1]}",
326+
"ip": "localhost",
327+
"port": {nodes[1].port}
328+
}},
329+
"replicas": []
330+
}},
331+
{{
332+
"slot_ranges": [
333+
{{
334+
"start": 10001,
335+
"end": 16383
336+
}}
337+
],
338+
"master": {{
339+
"id": "{node_ids[2]}",
340+
"ip": "localhost",
341+
"port": {nodes[2].port}
342+
}},
343+
"replicas": []
344+
}}
345+
]
346+
"""
347+
await push_config(config, c_nodes_admin)
348+
349+
client = aioredis.RedisCluster(decode_responses=True, host="localhost", port=nodes[0].port)
350+
351+
for i in range(10_000):
352+
key = 'key' + str(i)
353+
assert await client.set(key, 'value') == True
354+
assert await client.get(key) == 'value'
355+
356+
# Push new config
357+
config = f"""
358+
[
359+
{{
360+
"slot_ranges": [
361+
{{
362+
"start": 0,
363+
"end": 4000
364+
}}
365+
],
366+
"master": {{
367+
"id": "{node_ids[0]}",
368+
"ip": "localhost",
369+
"port": {nodes[0].port}
370+
}},
371+
"replicas": []
372+
}},
373+
{{
374+
"slot_ranges": [
375+
{{
376+
"start": 4001,
377+
"end": 14000
378+
}}
379+
],
380+
"master": {{
381+
"id": "{node_ids[1]}",
382+
"ip": "localhost",
383+
"port": {nodes[1].port}
384+
}},
385+
"replicas": []
386+
}},
387+
{{
388+
"slot_ranges": [
389+
{{
390+
"start": 14001,
391+
"end": 16383
392+
}}
393+
],
394+
"master": {{
395+
"id": "{node_ids[2]}",
396+
"ip": "localhost",
397+
"port": {nodes[2].port}
398+
}},
399+
"replicas": []
400+
}}
401+
]
402+
"""
403+
await push_config(config, c_nodes_admin)
404+
405+
for i in range(10_000):
406+
key = 'key' + str(i)
407+
assert await client.set(key, 'value') == True
408+
assert await client.get(key) == 'value'
409+
410+
await client.close()

0 commit comments

Comments
 (0)