Ejemplo n.º 1
0
async def test_get_running_tasks() -> None:
    async def inspect() -> None:
        await wait_all_tasks_blocked()
        new_tasks = set(get_running_tasks()) - existing_tasks
        task_infos[:] = sorted(new_tasks, key=lambda info: info.name or "")
        event.set()

    event = Event()
    task_infos: List[TaskInfo] = []
    host_task = get_current_task()
    async with create_task_group() as tg:
        existing_tasks = set(get_running_tasks())
        tg.start_soon(event.wait, name="task1")
        tg.start_soon(event.wait, name="task2")
        tg.start_soon(inspect)

    assert len(task_infos) == 3
    expected_names = [
        "task1",
        "task2",
        "tests.test_debugging.test_get_running_tasks.<locals>.inspect",
    ]
    for task, expected_name in zip(task_infos, expected_names):
        assert task.parent_id == host_task.id
        assert task.name == expected_name
        assert repr(task) == f"TaskInfo(id={task.id}, name={expected_name!r})"
Ejemplo n.º 2
0
async def test_get_running_tasks():
    event = create_event()
    async with create_task_group() as tg:
        existing_tasks = set(get_running_tasks())
        await tg.spawn(event.wait, name='task1')
        await tg.spawn(event.wait, name='task2')
        await wait_all_tasks_blocked()
        task_infos = set(get_running_tasks()) - existing_tasks
        await event.set()

    task_infos = sorted(task_infos, key=lambda info: info.name or '')
    assert len(task_infos) == 2
    assert task_infos[0].name == 'task1'
    assert task_infos[1].name == 'task2'
    assert re.fullmatch(r"TaskInfo\(id=\d+, name='task1'\)",
                        repr(task_infos[0]))
    assert re.fullmatch(r"TaskInfo\(id=\d+, name='task2'\)",
                        repr(task_infos[1]))
Ejemplo n.º 3
0
async def test_get_running_tasks():
    async def inspect():
        await wait_all_tasks_blocked()
        new_tasks = set(get_running_tasks()) - existing_tasks
        task_infos[:] = sorted(new_tasks, key=lambda info: info.name or '')
        event.set()

    event = create_event()
    task_infos = []
    host_task = get_current_task()
    async with create_task_group() as tg:
        existing_tasks = set(get_running_tasks())
        tg.spawn(event.wait, name='task1')
        tg.spawn(event.wait, name='task2')
        tg.spawn(inspect)

    assert len(task_infos) == 3
    expected_names = ['task1', 'task2', 'test_debugging.test_get_running_tasks.<locals>.inspect']
    for task, expected_name in zip(task_infos, expected_names):
        assert task.parent_id == host_task.id
        assert task.name == expected_name
        assert repr(task) == f'TaskInfo(id={task.id}, name={expected_name!r})'
Ejemplo n.º 4
0
 async def inspect() -> None:
     await wait_all_tasks_blocked()
     new_tasks = set(get_running_tasks()) - existing_tasks
     task_infos[:] = sorted(new_tasks, key=lambda info: info.name or "")
     event.set()
Ejemplo n.º 5
0
 async def test_get_running_tasks(self) -> None:
     tasks = await maybe_async(get_running_tasks())
     assert type(tasks) is list