@@ -50,7 +50,10 @@ def test_borrow_and_return(self):
5050 session .cluster .connection_factory .return_value = conn
5151
5252 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
53- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
53+ session .cluster .connection_factory .assert_called_once_with (
54+ host .endpoint ,
55+ _raise_on_startup_close = True ,
56+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
5457
5558 c , request_id = pool .borrow_connection (timeout = 0.01 )
5659 assert c is conn
@@ -69,7 +72,10 @@ def test_failed_wait_for_connection(self):
6972 session .cluster .connection_factory .return_value = conn
7073
7174 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
72- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
75+ session .cluster .connection_factory .assert_called_once_with (
76+ host .endpoint ,
77+ _raise_on_startup_close = True ,
78+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
7379
7480 pool .borrow_connection (timeout = 0.01 )
7581 assert 1 == conn .in_flight
@@ -89,7 +95,10 @@ def test_successful_wait_for_connection(self):
8995 session .cluster .connection_factory .return_value = conn
9096
9197 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
92- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
98+ session .cluster .connection_factory .assert_called_once_with (
99+ host .endpoint ,
100+ _raise_on_startup_close = True ,
101+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
93102
94103 pool .borrow_connection (timeout = 0.01 )
95104 assert 1 == conn .in_flight
@@ -114,7 +123,10 @@ def test_spawn_when_at_max(self):
114123 session .cluster .connection_factory .return_value = conn
115124
116125 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
117- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
126+ session .cluster .connection_factory .assert_called_once_with (
127+ host .endpoint ,
128+ _raise_on_startup_close = True ,
129+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
118130
119131 pool .borrow_connection (timeout = 0.01 )
120132 assert 1 == conn .in_flight
@@ -138,7 +150,10 @@ def test_return_defunct_connection(self):
138150 session .cluster .connection_factory .return_value = conn
139151
140152 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
141- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
153+ session .cluster .connection_factory .assert_called_once_with (
154+ host .endpoint ,
155+ _raise_on_startup_close = True ,
156+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
142157
143158 pool .borrow_connection (timeout = 0.01 )
144159 conn .is_defunct = True
@@ -160,7 +175,10 @@ def test_return_defunct_connection_on_down_host(self):
160175 session .cluster .shard_aware_options = ShardAwareOptions ()
161176
162177 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
163- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
178+ session .cluster .connection_factory .assert_called_once_with (
179+ host .endpoint ,
180+ _raise_on_startup_close = True ,
181+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
164182
165183 pool .borrow_connection (timeout = 0.01 )
166184 conn .is_defunct = True
@@ -187,7 +205,10 @@ def test_return_closed_connection(self):
187205 session .cluster .connection_factory .return_value = conn
188206
189207 pool = self .PoolImpl (host , HostDistance .LOCAL , session )
190- session .cluster .connection_factory .assert_called_once_with (host .endpoint , on_orphaned_stream_released = pool .on_orphaned_stream_released )
208+ session .cluster .connection_factory .assert_called_once_with (
209+ host .endpoint ,
210+ _raise_on_startup_close = True ,
211+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
191212
192213 pool .borrow_connection (timeout = 0.01 )
193214 conn .is_closed = True
@@ -230,6 +251,32 @@ class HostConnectionTests(_PoolTests):
230251 PoolImpl = HostConnection
231252 uses_single_connection = True
232253
254+ def test_replace_uses_startup_close_flag_without_pending_registration (self ):
255+ host = Mock (spec = Host , address = 'ip1' )
256+ host .sharding_info = None
257+ session = self .make_session ()
258+ first_conn = HashableMock (spec = Connection , in_flight = 0 , is_defunct = False ,
259+ is_closed = False , max_request_id = 100 )
260+ first_conn .features = ProtocolFeatures (shard_id = 0 )
261+ replacement_conn = HashableMock (spec = Connection , in_flight = 0 , is_defunct = False ,
262+ is_closed = False , max_request_id = 100 )
263+ replacement_conn .features = ProtocolFeatures (shard_id = 0 )
264+ session .cluster .connection_factory .side_effect = [first_conn , replacement_conn ]
265+
266+ pool = self .PoolImpl (host , HostDistance .LOCAL , session )
267+ session .cluster .connection_factory .reset_mock ()
268+ pool ._is_replacing = True
269+
270+ pool ._replace (first_conn )
271+
272+ session .cluster .connection_factory .assert_called_once_with (
273+ host .endpoint ,
274+ _raise_on_startup_close = True ,
275+ on_orphaned_stream_released = pool .on_orphaned_stream_released )
276+ assert pool ._pending_connections == []
277+ assert pool ._connections [0 ] is replacement_conn
278+ assert not pool ._is_replacing
279+
233280 def test_fast_shutdown (self ):
234281 class MockSession (MagicMock ):
235282 is_shutdown = False
0 commit comments