Skip to content

Commit

Permalink
Use caplog fixure rather than mock logging when testing HTEX shutdown (
Browse files Browse the repository at this point in the history
…#3559)

This replaces mock-captured call sequences which are over-testing the exact
position of tested log calls in relation to any other log calls, which makes
this test fragile when working on logs in the affected area of the code.

This is consistent with other parts of the test suite which test log messages
using caplog.
  • Loading branch information
benclifford authored Aug 1, 2024
1 parent 9c982c5 commit 7867b57
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions parsl/tests/test_htex/test_htex.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ def test_htex_start_encrypted(
@pytest.mark.local
@pytest.mark.parametrize("started", (True, False))
@pytest.mark.parametrize("timeout_expires", (True, False))
@mock.patch(f"{_MOCK_BASE}.logger")
def test_htex_shutdown(
mock_logger: mock.MagicMock,
started: bool,
timeout_expires: bool,
htex: HighThroughputExecutor,
caplog
):
mock_ix_proc = mock.Mock(spec=Popen)

Expand Down Expand Up @@ -110,20 +109,19 @@ def kill_interchange(*args, **kwargs):

htex.shutdown()

mock_logs = mock_logger.info.call_args_list
if started:
assert mock_ix_proc.terminate.called
assert mock_ix_proc.wait.called
assert {"timeout": 10} == mock_ix_proc.wait.call_args[1]
if timeout_expires:
assert "Unable to terminate Interchange" in mock_logs[1][0][0]
assert "Unable to terminate Interchange" in caplog.text
assert mock_ix_proc.kill.called
assert "Attempting" in mock_logs[0][0][0]
assert "Finished" in mock_logs[-1][0][0]
assert "Attempting HighThroughputExecutor shutdown" in caplog.text
assert "Finished HighThroughputExecutor shutdown" in caplog.text
else:
assert not mock_ix_proc.terminate.called
assert not mock_ix_proc.wait.called
assert "has not started" in mock_logs[0][0][0]
assert "HighThroughputExecutor has not started" in caplog.text


@pytest.mark.local
Expand Down

0 comments on commit 7867b57

Please sign in to comment.