From 434ee5ef0501966410693faca129d635bc0a7457 Mon Sep 17 00:00:00 2001 From: Toby Coleman Date: Mon, 26 May 2025 21:57:06 +0100 Subject: [PATCH 1/2] Fix flaky test --- tests/integration/test_process_stop_event.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_process_stop_event.py b/tests/integration/test_process_stop_event.py index 26cb485f..cf580c4b 100644 --- a/tests/integration/test_process_stop_event.py +++ b/tests/integration/test_process_stop_event.py @@ -103,7 +103,8 @@ async def stop_after() -> None: # StopEvent is sent half way through iter n+1, where n=iters_before_stop. The event will be # processed by component A in the iter following this one. A does not need to wait for # inputs before executing step, hence the step count reaches n+2 before stopping. - assert comp_a.step_count == iters_before_stop + 2 + # Allow a tolerance of +/- 1 + assert comp_a.step_count == pytest.approx(iters_before_stop + 2, abs=1) # Because A sleeps for sleep_time seconds before sending outputs, the B components, which # block waiting for field or event inputs, will receive the StopEvent before A sends @@ -111,12 +112,12 @@ async def stop_after() -> None: # inputs, and the StopEvent interrupts them before calling step, hence the count reaches n, for c in [comp_b1, comp_b2, comp_b3, comp_b4, comp_b5]: assert c.is_finished - assert c.step_count == iters_before_stop + assert c.step_count == pytest.approx(iters_before_stop, abs=1) # A performs n+1 full steps and is interrupted on step n+2 before a final update of out_1, # hence n+2. - assert comp_a.out_1 == iters_before_stop + 2 + assert comp_a.out_1 == pytest.approx(iters_before_stop + 2, abs=1) # Because the B components receive the StopEvent on iter n+1, they will only receive n # outputs from A before shutting down the IOController, hence n. for c in [comp_b1, comp_b2, comp_b3, comp_b4, comp_b5]: - assert c.in_1 == iters_before_stop + assert c.in_1 == pytest.approx(iters_before_stop, abs=1) From dfc1131c23bf99a919117a4e3131cefcda16e35b Mon Sep 17 00:00:00 2001 From: Toby Coleman Date: Mon, 26 May 2025 22:03:10 +0100 Subject: [PATCH 2/2] Put tolerance into constant --- tests/integration/test_process_stop_event.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_process_stop_event.py b/tests/integration/test_process_stop_event.py index cf580c4b..931ba082 100644 --- a/tests/integration/test_process_stop_event.py +++ b/tests/integration/test_process_stop_event.py @@ -19,6 +19,9 @@ from tests.conftest import ComponentTestHelper, zmq_connector_cls +STOP_TOLERANCE = 1 + + class A(ComponentTestHelper): io = IO(outputs=["out_1"]) @@ -104,7 +107,7 @@ async def stop_after() -> None: # processed by component A in the iter following this one. A does not need to wait for # inputs before executing step, hence the step count reaches n+2 before stopping. # Allow a tolerance of +/- 1 - assert comp_a.step_count == pytest.approx(iters_before_stop + 2, abs=1) + assert comp_a.step_count == pytest.approx(iters_before_stop + 2, abs=STOP_TOLERANCE) # Because A sleeps for sleep_time seconds before sending outputs, the B components, which # block waiting for field or event inputs, will receive the StopEvent before A sends @@ -112,12 +115,12 @@ async def stop_after() -> None: # inputs, and the StopEvent interrupts them before calling step, hence the count reaches n, for c in [comp_b1, comp_b2, comp_b3, comp_b4, comp_b5]: assert c.is_finished - assert c.step_count == pytest.approx(iters_before_stop, abs=1) + assert c.step_count == pytest.approx(iters_before_stop, abs=STOP_TOLERANCE) # A performs n+1 full steps and is interrupted on step n+2 before a final update of out_1, # hence n+2. - assert comp_a.out_1 == pytest.approx(iters_before_stop + 2, abs=1) + assert comp_a.out_1 == pytest.approx(iters_before_stop + 2, abs=STOP_TOLERANCE) # Because the B components receive the StopEvent on iter n+1, they will only receive n # outputs from A before shutting down the IOController, hence n. for c in [comp_b1, comp_b2, comp_b3, comp_b4, comp_b5]: - assert c.in_1 == pytest.approx(iters_before_stop, abs=1) + assert c.in_1 == pytest.approx(iters_before_stop, abs=STOP_TOLERANCE)