Skip to content

Commit

Permalink
Add daemonic task tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Booth committed Mar 6, 2021
1 parent 0266c1d commit f04c69c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,36 @@ async def test_task_group_bad_result_exception():
task1.cancel()


@pytest.mark.asyncio
async def test_daemon_tasks_not_waited_for_and_cancelled():
evt = Event()
async def wait_forever():
await evt.wait()

async with TaskGroup() as g:
d = await g.spawn(wait_forever, daemon=True)
t = await g.spawn(return_value, 5, 0.005)
assert g.tasks == {t}
assert g.daemons == {d}

assert d.cancelled()
assert g.result() == 5
assert g.exception() is None


@pytest.mark.asyncio
async def test_daemon_task_errors_ignored():
async with TaskGroup() as g:
d = await g.spawn(my_raises(ArithmeticError), daemon=True)
t = await g.spawn(return_value, 5, 0.005)
assert g.tasks == {t}
assert g.daemons == {d}
await sleep(0.01)

assert g.result() == 5
assert g.exception() is None


def test_TaskTimeout_str():
t = TaskTimeout(0.5)
assert str(t) == 'task timed out after 0.5s'

0 comments on commit f04c69c

Please sign in to comment.