示例#1
0
def test_parallel_debug_info():
    w1 = WaitState('w1', 0.3)
    w2 = WaitState('w2', 0.3)
    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.interrupt()
示例#2
0
def test_parallel_state_performance(capsys):

    wait_state_list = []
    for i in range(0, 1000):
        wait_state_list.append(WaitState(f"wait{i}", 1))

    pm = ParallelState('pm', wait_state_list)
    exe = Machine("xe", pm, rate=10)
    start_time = time.time()
    exe.start(None)
    pm.wait()
    exe.interrupt()
    duration = time.time() - start_time
    assert duration < 2  # as long as its not too slow, we are fine.
    assert not pm._run_thread.is_alive()
示例#3
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()