Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tests/integration/test_process_stop_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from tests.conftest import ComponentTestHelper, zmq_connector_cls


STOP_TOLERANCE = 1


class A(ComponentTestHelper):
io = IO(outputs=["out_1"])

Expand Down Expand Up @@ -103,20 +106,21 @@ 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
# the final output and then shutdown. B components cannot call step until they receive
# 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)
Loading