diff --git a/tests/integration/test_process_stop_event.py b/tests/integration/test_process_stop_event.py index 26cb485f..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"]) @@ -103,7 +106,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=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 @@ -111,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 == iters_before_stop + 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 == iters_before_stop + 2 + 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 == iters_before_stop + assert c.in_1 == pytest.approx(iters_before_stop, abs=STOP_TOLERANCE)