Skip to content

Commit

Permalink
Return error on timeout (bugfix) (#1302)
Browse files Browse the repository at this point in the history
Return error on timeout
  • Loading branch information
Hook25 authored Jun 20, 2024
1 parent a93851c commit 8a9c908
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion checkbox-ng/checkbox_ng/launcher/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def invoked(self, ctx):
print(".", end="", flush=True)
time.sleep(1)
else:
print(_("\nConnection timed out."))
raise SystemExit(_("\nConnection timed out."))

def check_remote_api_match(self):
"""
Expand Down
32 changes: 32 additions & 0 deletions checkbox-ng/checkbox_ng/launcher/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ def test_invoked_ok_for_localhost(

self.assertTrue(self_mock.connect_and_run.called)

@mock.patch("checkbox_ng.launcher.controller.is_hostname_a_loopback")
@mock.patch("time.time")
@mock.patch("time.sleep")
@mock.patch("builtins.print")
@mock.patch("checkbox_ng.launcher.controller.Configuration.from_text")
@mock.patch("checkbox_ng.launcher.controller._")
def test_invoked_err_timeout(
self,
gettext_mock,
configuration_mock,
print_mock,
time_sleep_mock,
time_mock,
loopback_check,
):
ctx_mock = mock.MagicMock()
ctx_mock.args.launcher = None
ctx_mock.args.user = "some username"
ctx_mock.args.host = "undertest@local"
ctx_mock.args.port = "9999"
loopback_check.return_value = True

self_mock = mock.MagicMock()
self_mock.connect_and_run.side_effect = ConnectionRefusedError

# intentionally cause the timeout
# we do 1 iteration, then we blow up due to timeout
time_mock.side_effect = [0, 0, 2e10]

with self.assertRaises(SystemExit):
RemoteController.invoked(self_mock, ctx_mock)

@mock.patch("checkbox_ng.launcher.controller.RemoteSessionAssistant")
def test_check_remote_api_match_ok(self, remote_assistant_mock):
"""
Expand Down

0 comments on commit 8a9c908

Please sign in to comment.