22
22
BASE_PORT = 30001
23
23
24
24
25
+ def monotonically_increasing_port_number ():
26
+ port = BASE_PORT
27
+ while True :
28
+ yield port
29
+ port = port + 1
30
+
31
+
32
+ # Create a generator object
33
+ next_port = monotonically_increasing_port_number ()
34
+
35
+
25
36
class RedisClusterNode :
26
37
def __init__ (self , port ):
27
38
self .port = port
@@ -279,8 +290,8 @@ def is_local_host(ip: str) -> bool:
279
290
# are hidden from users, see https://github.com/dragonflydb/dragonfly/issues/4173
280
291
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "emulated" , "managed_service_info" : "true" })
281
292
async def test_emulated_cluster_with_replicas (df_factory ):
282
- master = df_factory .create (port = BASE_PORT , admin_port = BASE_PORT + 1000 )
283
- replicas = [df_factory .create (port = BASE_PORT + i , logtostdout = True ) for i in range (1 , 3 )]
293
+ master = df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) )
294
+ replicas = [df_factory .create (port = next ( next_port ) , logtostdout = True ) for i in range (1 , 3 )]
284
295
285
296
df_factory .start_all ([master , * replicas ])
286
297
@@ -379,8 +390,8 @@ async def test_emulated_cluster_with_replicas(df_factory):
379
390
380
391
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" })
381
392
async def test_cluster_managed_service_info (df_factory ):
382
- master = df_factory .create (port = BASE_PORT , admin_port = BASE_PORT + 100 )
383
- replica = df_factory .create (port = BASE_PORT + 1 , admin_port = BASE_PORT + 101 )
393
+ master = df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) )
394
+ replica = df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) )
384
395
385
396
df_factory .start_all ([master , replica ])
386
397
@@ -561,7 +572,7 @@ async def test_cluster_nodes(df_server, async_client):
561
572
562
573
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" , "cluster_node_id" : "inigo montoya" })
563
574
async def test_cluster_node_id (df_factory : DflyInstanceFactory ):
564
- node = df_factory .create (port = BASE_PORT )
575
+ node = df_factory .create (port = next ( next_port ) )
565
576
df_factory .start_all ([node ])
566
577
567
578
conn = node .client ()
@@ -571,9 +582,7 @@ async def test_cluster_node_id(df_factory: DflyInstanceFactory):
571
582
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" })
572
583
async def test_cluster_slot_ownership_changes (df_factory : DflyInstanceFactory ):
573
584
# Start and configure cluster with 2 nodes
574
- nodes = [
575
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
576
- ]
585
+ nodes = [df_factory .create (port = next (next_port ), admin_port = next (next_port )) for i in range (2 )]
577
586
578
587
df_factory .start_all (nodes )
579
588
@@ -640,7 +649,7 @@ async def test_cluster_slot_ownership_changes(df_factory: DflyInstanceFactory):
640
649
await c_nodes [1 ].set ("KEY1" , "value" )
641
650
assert False , "Should not be able to set key on non-owner cluster node"
642
651
except redis .exceptions .ResponseError as e :
643
- assert e .args [0 ] == "MOVED 5259 localhost:30001 "
652
+ assert e .args [0 ] == f "MOVED 5259 localhost:{ nodes [ 0 ]. port } "
644
653
645
654
# And that node1 only has 1 key ("KEY2")
646
655
assert await c_nodes [1 ].execute_command ("DBSIZE" ) == 1
@@ -664,7 +673,7 @@ async def test_cluster_slot_ownership_changes(df_factory: DflyInstanceFactory):
664
673
await c_nodes [0 ].set ("KEY1" , "value" )
665
674
assert False , "Should not be able to set key on non-owner cluster node"
666
675
except redis .exceptions .ResponseError as e :
667
- assert e .args [0 ] == "MOVED 5259 localhost:30002 "
676
+ assert e .args [0 ] == f "MOVED 5259 localhost:{ nodes [ 1 ]. port } "
668
677
669
678
# And node1 should own it and allow using it
670
679
assert await c_nodes [1 ].set ("KEY1" , "value" )
@@ -699,8 +708,8 @@ async def test_cluster_slot_ownership_changes(df_factory: DflyInstanceFactory):
699
708
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" })
700
709
async def test_cluster_replica_sets_non_owned_keys (df_factory : DflyInstanceFactory ):
701
710
# Start and configure cluster with 1 master and 1 replica, both own all slots
702
- master = df_factory .create (admin_port = BASE_PORT + 1000 )
703
- replica = df_factory .create (admin_port = BASE_PORT + 1001 )
711
+ master = df_factory .create (admin_port = next ( next_port ) )
712
+ replica = df_factory .create (admin_port = next ( next_port ) )
704
713
df_factory .start_all ([master , replica ])
705
714
706
715
async with master .client () as c_master , master .admin_client () as c_master_admin , replica .client () as c_replica , replica .admin_client () as c_replica_admin :
@@ -807,8 +816,8 @@ async def test_cluster_replica_sets_non_owned_keys(df_factory: DflyInstanceFacto
807
816
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" })
808
817
async def test_cluster_flush_slots_after_config_change (df_factory : DflyInstanceFactory ):
809
818
# Start and configure cluster with 1 master and 1 replica, both own all slots
810
- master = df_factory .create (port = BASE_PORT , admin_port = BASE_PORT + 1000 )
811
- replica = df_factory .create (port = BASE_PORT + 1 , admin_port = BASE_PORT + 1001 )
819
+ master = df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) )
820
+ replica = df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) )
812
821
df_factory .start_all ([master , replica ])
813
822
814
823
c_master = master .client ()
@@ -958,7 +967,7 @@ async def test_cluster_blocking_command(df_server):
958
967
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" })
959
968
async def test_blocking_commands_cancel (df_factory , df_seeder_factory ):
960
969
instances = [
961
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
970
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
962
971
]
963
972
964
973
df_factory .start_all (instances )
@@ -987,11 +996,11 @@ async def test_blocking_commands_cancel(df_factory, df_seeder_factory):
987
996
988
997
with pytest .raises (aioredis .ResponseError ) as set_e_info :
989
998
await set_task
990
- assert "MOVED 3037 127.0.0.1:30002 " == str (set_e_info .value )
999
+ assert f "MOVED 3037 127.0.0.1:{ instances [ 1 ]. port } " == str (set_e_info .value )
991
1000
992
1001
with pytest .raises (aioredis .ResponseError ) as list_e_info :
993
1002
await list_task
994
- assert "MOVED 7141 127.0.0.1:30002 " == str (list_e_info .value )
1003
+ assert f "MOVED 7141 127.0.0.1:{ instances [ 1 ]. port } " == str (list_e_info .value )
995
1004
996
1005
997
1006
@pytest .mark .parametrize ("set_cluster_node_id" , [True , False ])
@@ -1004,8 +1013,8 @@ async def test_cluster_native_client(
1004
1013
# Start and configure cluster with 3 masters and 3 replicas
1005
1014
masters = [
1006
1015
df_factory .create (
1007
- port = BASE_PORT + i ,
1008
- admin_port = BASE_PORT + i + 1000 ,
1016
+ port = next ( next_port ) ,
1017
+ admin_port = next ( next_port ) ,
1009
1018
cluster_node_id = f"master{ i } " if set_cluster_node_id else "" ,
1010
1019
)
1011
1020
for i in range (3 )
@@ -1017,10 +1026,10 @@ async def test_cluster_native_client(
1017
1026
1018
1027
replicas = [
1019
1028
df_factory .create (
1020
- port = BASE_PORT + 100 + i ,
1021
- admin_port = BASE_PORT + i + 1100 ,
1029
+ port = next ( next_port ) ,
1030
+ admin_port = next ( next_port ) ,
1022
1031
cluster_node_id = f"replica{ i } " if set_cluster_node_id else "" ,
1023
- replicaof = f"localhost:{ BASE_PORT + i } " ,
1032
+ replicaof = f"localhost:{ masters [ i ]. port } " ,
1024
1033
)
1025
1034
for i in range (3 )
1026
1035
]
@@ -1195,7 +1204,7 @@ async def test_random_keys():
1195
1204
async def test_config_consistency (df_factory : DflyInstanceFactory ):
1196
1205
# Check slot migration from one node to another
1197
1206
instances = [
1198
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
1207
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1199
1208
]
1200
1209
1201
1210
df_factory .start_all (instances )
@@ -1245,8 +1254,8 @@ async def test_cluster_flushall_during_migration(
1245
1254
# Check data migration from one node to another
1246
1255
instances = [
1247
1256
df_factory .create (
1248
- port = BASE_PORT + i ,
1249
- admin_port = BASE_PORT + i + 1000 ,
1257
+ port = next ( next_port ) ,
1258
+ admin_port = next ( next_port ) ,
1250
1259
vmodule = "cluster_family=9,outgoing_slot_migration=9,incoming_slot_migration=9" ,
1251
1260
logtostdout = True ,
1252
1261
)
@@ -1298,8 +1307,8 @@ async def test_cluster_data_migration(df_factory: DflyInstanceFactory, interrupt
1298
1307
# Check data migration from one node to another
1299
1308
instances = [
1300
1309
df_factory .create (
1301
- port = BASE_PORT + i ,
1302
- admin_port = BASE_PORT + i + 1000 ,
1310
+ port = next ( next_port ) ,
1311
+ admin_port = next ( next_port ) ,
1303
1312
vmodule = "outgoing_slot_migration=9,cluster_family=9,incoming_slot_migration=9,streamer=9" ,
1304
1313
)
1305
1314
for i in range (2 )
@@ -1378,7 +1387,7 @@ async def test_cluster_data_migration(df_factory: DflyInstanceFactory, interrupt
1378
1387
@dfly_args ({"proactor_threads" : 2 , "cluster_mode" : "yes" , "cache_mode" : "true" })
1379
1388
async def test_migration_with_key_ttl (df_factory ):
1380
1389
instances = [
1381
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
1390
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1382
1391
]
1383
1392
1384
1393
df_factory .start_all (instances )
@@ -1427,7 +1436,7 @@ async def test_migration_with_key_ttl(df_factory):
1427
1436
@dfly_args ({"proactor_threads" : 4 , "cluster_mode" : "yes" , "serialization_max_chunk_size" : 0 })
1428
1437
async def test_network_disconnect_during_migration (df_factory ):
1429
1438
instances = [
1430
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
1439
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1431
1440
]
1432
1441
1433
1442
df_factory .start_all (instances )
@@ -1496,8 +1505,8 @@ async def test_cluster_fuzzymigration(
1496
1505
):
1497
1506
instances = [
1498
1507
df_factory .create (
1499
- port = BASE_PORT + i ,
1500
- admin_port = BASE_PORT + i + 1000 ,
1508
+ port = next ( next_port ) ,
1509
+ admin_port = next ( next_port ) ,
1501
1510
vmodule = "outgoing_slot_migration=9,cluster_family=9,incoming_slot_migration=9" ,
1502
1511
serialization_max_chunk_size = huge_values ,
1503
1512
replication_stream_output_limit = 10 ,
@@ -1632,7 +1641,7 @@ async def test_all_finished():
1632
1641
async def test_cluster_config_reapply (df_factory : DflyInstanceFactory ):
1633
1642
"""Check data migration from one node to another."""
1634
1643
instances = [
1635
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
1644
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1636
1645
]
1637
1646
df_factory .start_all (instances )
1638
1647
@@ -1690,7 +1699,7 @@ async def test_cluster_replication_migration(
1690
1699
and make sure the captures on the replicas are equal.
1691
1700
"""
1692
1701
instances = [
1693
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + 1000 + i ) for i in range (4 )
1702
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (4 )
1694
1703
]
1695
1704
df_factory .start_all (instances )
1696
1705
@@ -1767,7 +1776,7 @@ async def test_start_replication_during_migration(
1767
1776
in the end master_1 and replica_1 should have the same data
1768
1777
"""
1769
1778
instances = [
1770
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + 1000 + i ) for i in range (3 )
1779
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (3 )
1771
1780
]
1772
1781
df_factory .start_all (instances )
1773
1782
@@ -1834,7 +1843,7 @@ async def test_snapshoting_during_migration(
1834
1843
The result should be the same: snapshot contains all the data that existed before migration
1835
1844
"""
1836
1845
instances = [
1837
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + 1000 + i ) for i in range (2 )
1846
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1838
1847
]
1839
1848
df_factory .start_all (instances )
1840
1849
@@ -1904,7 +1913,7 @@ async def start_save():
1904
1913
async def test_cluster_migration_cancel (df_factory : DflyInstanceFactory ):
1905
1914
"""Check data migration from one node to another."""
1906
1915
instances = [
1907
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
1916
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1908
1917
]
1909
1918
df_factory .start_all (instances )
1910
1919
@@ -1965,7 +1974,7 @@ async def node1size0():
1965
1974
@pytest .mark .asyncio
1966
1975
async def test_cluster_migration_huge_container (df_factory : DflyInstanceFactory ):
1967
1976
instances = [
1968
- df_factory .create (port = BASE_PORT + i , admin_port = BASE_PORT + i + 1000 ) for i in range (2 )
1977
+ df_factory .create (port = next ( next_port ) , admin_port = next ( next_port ) ) for i in range (2 )
1969
1978
]
1970
1979
df_factory .start_all (instances )
1971
1980
@@ -2027,9 +2036,9 @@ async def test_replicate_cluster(df_factory: DflyInstanceFactory, df_seeder_fact
2027
2036
Send traffic before replication start and while replicating.
2028
2037
Promote the replica to master and check data consistency between cluster and single node.
2029
2038
"""
2030
- replica = df_factory .create (admin_port = BASE_PORT , cluster_mode = "emulated" )
2039
+ replica = df_factory .create (admin_port = next ( next_port ) , cluster_mode = "emulated" )
2031
2040
cluster_nodes = [
2032
- df_factory .create (admin_port = BASE_PORT + i + 1 , cluster_mode = "yes" ) for i in range (2 )
2041
+ df_factory .create (admin_port = next ( next_port ) , cluster_mode = "yes" ) for i in range (2 )
2033
2042
]
2034
2043
2035
2044
# Start instances and connect clients
@@ -2114,9 +2123,9 @@ async def test_replicate_disconnect_cluster(df_factory: DflyInstanceFactory, df_
2114
2123
Promote replica to master
2115
2124
Compare cluster data and replica data
2116
2125
"""
2117
- replica = df_factory .create (admin_port = BASE_PORT , cluster_mode = "emulated" )
2126
+ replica = df_factory .create (admin_port = next ( next_port ) , cluster_mode = "emulated" )
2118
2127
cluster_nodes = [
2119
- df_factory .create (admin_port = BASE_PORT + i + 1 , cluster_mode = "yes" ) for i in range (2 )
2128
+ df_factory .create (admin_port = next ( next_port ) , cluster_mode = "yes" ) for i in range (2 )
2120
2129
]
2121
2130
2122
2131
# Start instances and connect clients
@@ -2228,7 +2237,7 @@ async def test_replicate_redis_cluster(redis_cluster, df_factory, df_seeder_fact
2228
2237
Send traffic before replication start and while replicating.
2229
2238
Promote the replica to master and check data consistency between cluster and single dragonfly node.
2230
2239
"""
2231
- replica = df_factory .create (admin_port = BASE_PORT , cluster_mode = "emulated" )
2240
+ replica = df_factory .create (admin_port = next ( next_port ) , cluster_mode = "emulated" )
2232
2241
2233
2242
# Start instances and connect clients
2234
2243
df_factory .start_all ([replica ])
@@ -2286,7 +2295,7 @@ async def test_replicate_disconnect_redis_cluster(redis_cluster, df_factory, df_
2286
2295
Send more traffic
2287
2296
Promote the replica to master and check data consistency between cluster and single dragonfly node.
2288
2297
"""
2289
- replica = df_factory .create (admin_port = BASE_PORT , cluster_mode = "emulated" )
2298
+ replica = df_factory .create (admin_port = next ( next_port ) , cluster_mode = "emulated" )
2290
2299
2291
2300
# Start instances and connect clients
2292
2301
df_factory .start_all ([replica ])
@@ -2371,8 +2380,8 @@ async def test_cluster_memory_consumption_migration(df_factory: DflyInstanceFact
2371
2380
instances = [
2372
2381
df_factory .create (
2373
2382
maxmemory = "15G" ,
2374
- port = BASE_PORT + i ,
2375
- admin_port = BASE_PORT + i + 1000 ,
2383
+ port = next ( next_port ) ,
2384
+ admin_port = next ( next_port ) ,
2376
2385
vmodule = "streamer=9" ,
2377
2386
)
2378
2387
for i in range (3 )
@@ -2429,8 +2438,8 @@ async def test_migration_timeout_on_sync(df_factory: DflyInstanceFactory, df_see
2429
2438
# Timeout set to 3 seconds because we must first saturate the socket before we get the timeout
2430
2439
instances = [
2431
2440
df_factory .create (
2432
- port = BASE_PORT + i ,
2433
- admin_port = BASE_PORT + i + 1000 ,
2441
+ port = next ( next_port ) ,
2442
+ admin_port = next ( next_port ) ,
2434
2443
replication_timeout = 3000 ,
2435
2444
vmodule = "outgoing_slot_migration=9,cluster_family=9,incoming_slot_migration=9,streamer=2" ,
2436
2445
)
0 commit comments