Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 560d82a

Browse files
committedJun 6, 2024
test: test for on_connect to handle HELLO command failure
1 parent 0b0ec5a commit 560d82a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

‎tests/test_connection.py

+33
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,39 @@ def test_on_connect(self, mock_read_response, mock_send_command):
178178

179179
mock_read_response.side_effect = itertools.repeat("OK")
180180

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+
181214

182215
@pytest.mark.onlynoncluster
183216
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)
Please sign in to comment.