Example #1
0
async def test_isolated_component(boot_info, log_listener, component, request,
                                  monkeypatch):
    # On overloaded CI machines it can sometimes take a while for a component's process to start,
    # so we need a high timeout here.
    component_timeout = 10
    monkeypatch.setenv('ASYNCIO_RUN_IN_PROCESS_STARTUP_TIMEOUT',
                       str(component_timeout))
    # Test the lifecycle management for isolated process components to be sure
    # they start and stop as expected
    component_manager = ComponentManager(boot_info, (component, ))

    async with background_asyncio_service(component_manager) as cm_manager:
        event_bus = await component_manager.get_event_bus()

        got_started = asyncio.Future()

        event_bus.subscribe(IsStarted,
                            lambda ev: got_started.set_result(ev.path))

        touch_path = await asyncio.wait_for(got_started,
                                            timeout=component_timeout)

        def delete_touch_path():
            if touch_path.exists():
                touch_path.unlink()

        request.addfinalizer(delete_touch_path)
        assert not touch_path.exists()
        component_manager.shutdown('exiting component manager')
        await cm_manager.wait_finished()

    assert touch_path.exists()
Example #2
0
async def test_asyncio_isolated_component(boot_info, log_listener):
    # Test the lifecycle management for isolated process components to be sure
    # they start and stop as expected
    component_manager = ComponentManager(boot_info,
                                         (AsyncioComponentForTest, ),
                                         lambda reason: None)

    async with background_asyncio_service(component_manager):
        event_bus = await component_manager.get_event_bus()

        got_started = asyncio.Future()

        event_bus.subscribe(IsStarted,
                            lambda ev: got_started.set_result(ev.path))

        touch_path = await asyncio.wait_for(got_started, timeout=10)
        assert not touch_path.exists()
        component_manager.shutdown('exiting component manager')

    for _ in range(10000):
        if not touch_path.exists():
            await asyncio.sleep(0.001)
        else:
            break
    else:
        assert touch_path.exists()
async def test_isolated_component(boot_info, log_listener, component, request):
    # Test the lifecycle management for isolated process components to be sure
    # they start and stop as expected
    component_manager = ComponentManager(boot_info, (component, ))

    async with background_asyncio_service(component_manager) as cm_manager:
        event_bus = await component_manager.get_event_bus()

        got_started = asyncio.Future()

        event_bus.subscribe(IsStarted,
                            lambda ev: got_started.set_result(ev.path))

        touch_path = await asyncio.wait_for(got_started, timeout=10)

        def delete_touch_path():
            if touch_path.exists():
                touch_path.unlink()

        request.addfinalizer(delete_touch_path)
        assert not touch_path.exists()
        component_manager.shutdown('exiting component manager')
        await cm_manager.wait_finished()

    assert touch_path.exists()