Esempio n. 1
0
async def test_actions_not_queued_for_seq_exec(short_start_delay):
    component, status_queue = create_component_with_status_queue({
        'name':
        'name',
        'args': ['sleep', '30'],
        'delay':
        0,
        'revive':
        False
    })

    while True:
        if await status_queue.get() == Status.RUNNING:
            break

    for _ in range(5):
        component.start()
        component.stop()
    assert (await status_queue.get() == Status.STOPPING)
    assert (await status_queue.get() == Status.STOPPED)

    await asyncio.sleep(0.001)
    assert status_queue.empty()

    await component.async_close()
Esempio n. 2
0
async def test_revive_on_stop(short_start_delay):
    component, status_queue = create_component_with_status_queue({
        'name':
        'comp-xy',
        'args': ['sleep', '30'],
        'delay':
        0,
        'revive':
        True
    })

    assert component.status == Status.STOPPED
    assert (await status_queue.get() == Status.STARTING)
    assert (await status_queue.get() == Status.RUNNING)
    for i in range(3):
        component.stop()
        assert (await status_queue.get() == Status.STOPPING)
        assert (await status_queue.get() == Status.STOPPED)
        assert (await status_queue.get() == Status.STARTING)
        assert (await status_queue.get() == Status.RUNNING)
    component.set_revive(False)
    await status_queue.get()
    component.stop()
    assert (await status_queue.get() == Status.STOPPING)
    assert (await status_queue.get() == Status.STOPPED)
    with pytest.raises(asyncio.TimeoutError):
        await asyncio.wait_for(status_queue.get(), timeout=0.01)
    component.set_revive(True)
    await status_queue.get()
    assert (await status_queue.get() == Status.STARTING)
    assert (await status_queue.get() == Status.RUNNING)
    assert status_queue.empty()
    await component.async_close()
    assert component.closed.done()
Esempio n. 3
0
async def test_noop_stop(short_start_delay):
    component, status_queue = create_component_with_status_queue({
        'name':
        'name',
        'args': ['sleep', '30'],
        'delay':
        0,
        'revive':
        False
    })

    await status_queue.get() == Status.STARTING
    component.stop()
    while True:
        if await status_queue.get() == Status.STOPPED:
            break

    for _ in range(5):
        component.stop()
    assert component.status == Status.STOPPED

    await asyncio.sleep(0.001)
    assert status_queue.empty()

    await component.async_close()
Esempio n. 4
0
async def test_starting_no_interrupt(short_start_delay):
    component, status_queue = create_component_with_status_queue({
        'name':
        'name',
        'args': ['sleep', '30'],
        'delay':
        0,
        'revive':
        False
    })

    assert component.status == Status.STOPPED
    assert (await status_queue.get() == Status.STARTING)

    for _ in range(5):
        component.start()
        component.stop()
    assert (await status_queue.get() == Status.RUNNING)
    assert (await status_queue.get() == Status.STOPPING)
    assert (await status_queue.get() == Status.STOPPED)

    await asyncio.sleep(0.001)
    assert status_queue.empty()

    await component.async_close()
Esempio n. 5
0
async def test_new_process_on_start(short_start_delay, process_queue):
    component, status_queue = create_component_with_status_queue({
        'name':
        'comp-xy',
        'args': ['sleep', '100'],
        'delay':
        0,
        'revive':
        False
    })

    for i in range(5):
        if i != 0:
            component.start()
        p = await process_queue.get()
        assert (await status_queue.get() == Status.STARTING)
        assert (await status_queue.get() == Status.RUNNING)
        assert p.returncode is None

        component.stop()
        assert (await status_queue.get() == Status.STOPPING)
        assert (await status_queue.get() == Status.STOPPED)
        assert p.returncode is not None

    await component.async_close()
    assert status_queue.empty()
    assert process_queue.empty()
Esempio n. 6
0
async def test_process_stopped_on_stop(short_start_delay, process_queue):
    component = Component({
        'name': 'name',
        'args': ['sleep', '10'],
        'delay': 0,
        'revive': False
    })
    p = await process_queue.get()
    assert p.returncode is None
    component.stop()
    while p.returncode is None:
        await asyncio.sleep(0.001)
    await component.async_close()
Esempio n. 7
0
async def test_stop_during_delay(short_start_delay):
    component, status_queue = create_component_with_status_queue({
        'name':
        'comp-xy',
        'args': ['sleep', '10'],
        'delay':
        1,
        'revive':
        False
    })

    assert component.status == Status.DELAYED
    component.stop()
    assert (await status_queue.get() == Status.STOPPED)
    assert status_queue.empty()
    await component.async_close()
    assert component.closed.done()
Esempio n. 8
0
async def test_delayed_start_stop(short_start_delay):
    component, status_queue = create_component_with_status_queue({
        'name':
        'comp-xy',
        'args': ['sleep', '30'],
        'delay':
        0.01,
        'revive':
        False
    })

    assert component.status == Status.DELAYED
    assert (await status_queue.get() == Status.STARTING)
    assert (await status_queue.get() == Status.RUNNING)
    component.stop()
    assert (await status_queue.get() == Status.STOPPING)
    assert (await status_queue.get() == Status.STOPPED)
    component.start()
    assert (await status_queue.get() == Status.STARTING)
    assert (await status_queue.get() == Status.RUNNING)
    assert status_queue.empty()
    await component.async_close()
    assert component.closed.done()
Esempio n. 9
0
 def _process_msg_stop(self, payload):
     component = self._components[payload['id']]
     component.stop()