def test_interruption_in_machines_with_sequential_state(capsys): ws1 = WaitState("ws1", 0.2) ws2 = WaitState("ws2", 0.2) ps1 = PrintState("ps1", "Print1") es = IdleState("es") iss = IdleState("iss") sm = SequentialState("sm", children=[ws1, ws2, ps1]) sm.add_transition_on_success(es) sm.add_transition(lambda s, b: s._curr_child.check_name('ws2'), iss) exe = Machine("exe", sm, ["es", "iss"], rate=100) exe.run() assert exe._exception_raised_state_name == "" assert exe._internal_exception is None assert exe._status == StateStatus.SUCCESS assert not exe._run_thread.is_alive() assert exe._curr_state._name == 'iss' assert exe.is_end() assert capsys.readouterr().out == "" assert not sm._run_thread.is_alive() assert not ws1._run_thread.is_alive() assert not ws2._run_thread.is_alive() assert sm._status == StateStatus.INTERRUPTED assert ws2._status == StateStatus.INTERRUPTED assert ws1._status == StateStatus.SUCCESS assert ps1._status == StateStatus.NOT_RUNNING assert ws2.check_status(StateStatus.INTERRUPTED) assert ws1.check_status(StateStatus.SUCCESS)
def test_parallel_state_in_machine(capsys): ws = WaitState("ws1", 1) ws2 = WaitState("ws2", 2) es = IdleState("es") pm = ParallelState('pm', [ws, ws2]) pm.add_transition_on_success(es) exe = Machine("main_machine", pm, end_state_ids=['es'], rate=10) # run machine and see how it reacts exe.start(None) # wait for one second assert not exe.wait(1.1) assert ws.check_status(StateStatus.SUCCESS) assert ws2.check_status(StateStatus.RUNNING) assert exe.check_status(StateStatus.RUNNING) # at this point ws should be done but ws2 is still going # wait another one seconds assert exe.wait(2) assert exe.check_status(StateStatus.SUCCESS) assert not pm._run_thread.is_alive()
def test_interruption_in_sequential_state(capsys): ws1 = WaitState("ws1", 0.1) ws2 = WaitState("ws2", 0.1) ps1 = PrintState("ps1", "Print1") sm = SequentialState("sm", children=[ws1, ws2, ps1]) sm.start(None) sm.wait(0.15) sm.interrupt() assert capsys.readouterr().out == "" assert sm.check_status(StateStatus.INTERRUPTED) assert ws2.check_status(StateStatus.INTERRUPTED) assert ws1.check_status(StateStatus.SUCCESS) assert ps1.check_status(StateStatus.NOT_RUNNING) assert not sm._run_thread.is_alive() assert not ws1._run_thread.is_alive() assert not ws2._run_thread.is_alive()