Skip to content

Commit

Permalink
Added test for #695
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Apr 4, 2024
1 parent 890602a commit f79b7b1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest
from exceptiongroup import catch
from pytest_mock import MockerFixture

import anyio
from anyio import (
Expand Down Expand Up @@ -249,6 +250,27 @@ async def taskfunc() -> None:
await task


@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_cancel_with_nested_shielded_scope(mocker: MockerFixture) -> None:
"""Regression test for #695."""

async def shield_task() -> None:
with CancelScope(shield=True):
await sleep(0.5)

async def task() -> None:
async with create_task_group() as tg:
tg.start_soon(shield_task)

async with create_task_group() as tg:
spy = mocker.spy(tg.cancel_scope, "_deliver_cancellation")
tg.start_soon(task)
await wait_all_tasks_blocked()
tg.cancel_scope.cancel()

assert len(spy.call_args_list) < 3


async def test_start_exception_delivery(anyio_backend_name: str) -> None:
def task_fn(*, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
task_status.started("hello")
Expand Down

0 comments on commit f79b7b1

Please sign in to comment.