@@ -178,6 +178,39 @@ def test_on_connect(self, mock_read_response, mock_send_command):
178
178
179
179
mock_read_response .side_effect = itertools .repeat ("OK" )
180
180
181
+ @patch .object (Connection , 'send_command' )
182
+ @patch .object (Connection , 'read_response' )
183
+ def test_on_connect_fail_hello (self , mock_read_response , mock_send_command ):
184
+ """Test that on_connect handles connection failure HELLO command"""
185
+ conn = Connection ()
186
+
187
+ conn ._parser = MagicMock ()
188
+ conn ._parser .on_connect .return_value = None
189
+ conn .credential_provider = None
190
+ conn .username = "myuser"
191
+ conn .password = "password"
192
+ conn .protocol = - 1 # invalid protocol
193
+ conn .client_name = "test-client"
194
+ conn .lib_name = "test"
195
+ conn .lib_version = "1234"
196
+ conn .db = 0
197
+ conn .client_cache = True
198
+
199
+ # simulate a failure in the HELLO command response
200
+ mock_read_response .side_effect = itertools .cycle ([
201
+ Exception ("Invalid RESP version" ), # HELLO (fails)
202
+ b'QUEUED' , # MULTI
203
+ ])
204
+
205
+ with self .assertRaises (ConnectionError ):
206
+ conn .on_connect ()
207
+
208
+ mock_send_command .assert_any_call ('HELLO' , - 1 , 'AUTH' , 'myuser' , 'password' ),
209
+
210
+ mock_send_command .assert_called ()
211
+ mock_read_response .assert_called ()
212
+
213
+
181
214
182
215
@pytest .mark .onlynoncluster
183
216
@pytest .mark .parametrize (
0 commit comments