コード例 #1
0
def test_parallel_debug_info():
    w1 = WaitState('w1', 1)
    w2 = WaitState('w2', 1)
    pm = ParallelState("pm", [w1, w2])
    pm.start(None)
    pm.wait(0.1)
    info = pm.get_debug_info()
    assert info['name'] == 'pm'
    assert len(info['children']) == 2
    assert info['children'][0]['name'] == 'w1'
    assert info['children'][0]['status'] == StateStatus.RUNNING
    assert info['children'][1]['name'] == 'w2'
    assert info['children'][1]['status'] == StateStatus.RUNNING
    pm.wait(1)
    pm.tick(None)
    pm.wait(0.1)
コード例 #2
0
def test_parallel_state_individual(capsys):

    ws = WaitState("ws1", 1)
    ws2 = WaitState("ws2", 2)

    pm = ParallelState('pm', [ws, ws2])

    pm.start(None)
    # wait for one second outside
    time.sleep(1)
    pm.tick(None)  # ticks to force event flags if any
    assert not pm.wait(0.1)
    assert pm.check_status(StateStatus.RUNNING)
    # at this point ws should be done but ws2 is still going
    time.sleep(1.1)
    pm.tick(None)  # ticks to force event flags if any
    # wait
    assert pm.wait(0.1)
    assert not pm.check_status(StateStatus.RUNNING)
    assert pm.check_status(StateStatus.SUCCESS)
    assert not pm._run_thread.is_alive()