@@ -579,6 +579,40 @@ def make_pool(host, distance, pool_session, endpoint=None):
579579 created_pools [1 ].shutdown .assert_not_called ()
580580 assert session ._pools [host ] is created_pools [1 ]
581581
582+ def test_on_up_does_not_publish_replacement_endpoint_pool_after_endpoint_swap (self ):
583+ host = self ._make_host ("127.0.0.1" )
584+ host .set_down ()
585+ old_endpoint = host .endpoint
586+ new_endpoint = DefaultEndPoint ("127.0.0.2" )
587+ cluster , session , executor = self ._make_cluster_and_session ([host ])
588+ created_pools = []
589+
590+ def make_pool (host , distance , pool_session , endpoint = None ):
591+ pool = self ._make_pool (host , distance , pool_session , endpoint )
592+ created_pools .append (pool )
593+ return pool
594+
595+ original_add_or_renew_pool = Session .add_or_renew_pool .__get__ (
596+ session , Session )
597+
598+ def add_after_endpoint_swap (host , * args , ** kwargs ):
599+ host .endpoint = new_endpoint
600+ return original_add_or_renew_pool (host , * args , ** kwargs )
601+
602+ session .add_or_renew_pool = Mock (side_effect = add_after_endpoint_swap )
603+
604+ with patch ("cassandra.cluster.HostConnection" , side_effect = make_pool ):
605+ Cluster .on_up (cluster , host )
606+ while executor .submissions :
607+ executor .run_next ()
608+
609+ assert created_pools == []
610+ assert session ._pools == {}
611+ session .add_or_renew_pool .assert_called_once_with (
612+ host , is_host_addition = False ,
613+ allow_retry_after_auth_failure = True ,
614+ expected_endpoint = old_endpoint )
615+
582616 def test_pool_creation_publishes_before_endpoint_lock_is_released (self ):
583617 host = self ._make_host ("127.0.0.1" )
584618 new_endpoint = DefaultEndPoint ("127.0.0.2" )
@@ -1750,7 +1784,8 @@ def queue_up_then_fail(h):
17501784 cluster .control_connection .on_up .assert_called_once_with (host )
17511785 session .add_or_renew_pool .assert_called_once_with (
17521786 host , is_host_addition = False ,
1753- allow_retry_after_auth_failure = True )
1787+ allow_retry_after_auth_failure = True ,
1788+ expected_endpoint = host .endpoint )
17541789 assert host .is_up
17551790 assert self ._state (cluster , host ).up_epoch is None
17561791 assert self ._state (cluster , host ).pending_up_epoch is None
0 commit comments