Skip to content

Commit

Permalink
WIP fix for #695
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Aug 7, 2024
1 parent 8907964 commit 278d4b6
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 @@ -257,6 +258,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 middle_task() -> None:
async with create_task_group() as tg:
tg.start_soon(shield_task, name="shield task")

async with create_task_group() as tg:
spy = mocker.spy(tg.cancel_scope, "_deliver_cancellation")
tg.start_soon(middle_task, name="middle 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 278d4b6

Please sign in to comment.