@@ -2262,6 +2262,57 @@ def test_init_slots_cache(self):
2262
2262
2263
2263
assert len (n_manager .nodes_cache ) == 6
2264
2264
2265
+ def test_init_promote_server_type_for_node_in_cache (self ):
2266
+ """
2267
+ When replica is promoted to master, nodes_cache must change the server type
2268
+ accordingly
2269
+ """
2270
+ cluster_slots_before_promotion = [
2271
+ [0 , 16383 , ["127.0.0.1" , 7000 ], ["127.0.0.1" , 7003 ]]
2272
+ ]
2273
+ cluster_slots_after_promotion = [
2274
+ [0 , 16383 , ["127.0.0.1" , 7003 ], ["127.0.0.1" , 7004 ]]
2275
+ ]
2276
+
2277
+ cluster_slots_results = [
2278
+ cluster_slots_before_promotion ,
2279
+ cluster_slots_after_promotion ,
2280
+ ]
2281
+
2282
+ with patch .object (Redis , "execute_command" ) as execute_command_mock :
2283
+
2284
+ def execute_command (* _args , ** _kwargs ):
2285
+ if _args [0 ] == "CLUSTER SLOTS" :
2286
+ mock_cluster_slots = cluster_slots_results .pop (0 )
2287
+ return mock_cluster_slots
2288
+ elif _args [0 ] == "COMMAND" :
2289
+ return {"get" : [], "set" : []}
2290
+ elif _args [0 ] == "INFO" :
2291
+ return {"cluster_enabled" : True }
2292
+ elif len (_args ) > 1 and _args [1 ] == "cluster-require-full-coverage" :
2293
+ return {"cluster-require-full-coverage" : False }
2294
+ else :
2295
+ return execute_command_mock (* _args , ** _kwargs )
2296
+
2297
+ execute_command_mock .side_effect = execute_command
2298
+
2299
+ nm = NodesManager (
2300
+ startup_nodes = [ClusterNode (host = default_host , port = default_port )],
2301
+ from_url = False ,
2302
+ require_full_coverage = False ,
2303
+ dynamic_startup_nodes = True ,
2304
+ )
2305
+
2306
+ assert nm .default_node .host == "127.0.0.1"
2307
+ assert nm .default_node .port == 7000
2308
+ assert nm .default_node .server_type == PRIMARY
2309
+
2310
+ nm .initialize ()
2311
+
2312
+ assert nm .default_node .host == "127.0.0.1"
2313
+ assert nm .default_node .port == 7003
2314
+ assert nm .default_node .server_type == PRIMARY
2315
+
2265
2316
def test_init_slots_cache_cluster_mode_disabled (self ):
2266
2317
"""
2267
2318
Test that creating a RedisCluster failes if one of the startup nodes
0 commit comments