forked from agronholm/anyio
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Event.wait() raising cancelled on asyncio when set() before scope…
… cancelled Fixes agronholm#536.
- Loading branch information
1 parent
bfdc46a
commit bcdedc4
Showing
5 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
from typing import Any, cast | ||
|
||
import pytest | ||
from _pytest.fixtures import getfixturemarker | ||
|
||
from anyio import create_task_group | ||
from anyio._backends._asyncio import cancelling | ||
from anyio.abc import TaskStatus | ||
from anyio.lowlevel import cancel_shielded_checkpoint, checkpoint | ||
from anyio.pytest_plugin import anyio_backend_name | ||
|
||
try: | ||
from .conftest import anyio_backend as parent_anyio_backend | ||
except ImportError: | ||
from ..conftest import anyio_backend as parent_anyio_backend | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
# Use the inherited anyio_backend, but filter out non-asyncio | ||
anyio_backend = pytest.fixture( | ||
params=[ | ||
param | ||
for param in cast(Any, getfixturemarker(parent_anyio_backend)).params | ||
if any( | ||
"asyncio" | ||
in anyio_backend_name.__wrapped__(backend) # type: ignore[attr-defined] | ||
for backend in param.values | ||
) | ||
] | ||
)(parent_anyio_backend.__wrapped__) | ||
|
||
|
||
async def test_cancelling() -> None: | ||
async def func(*, task_status: TaskStatus[asyncio.Task]) -> None: | ||
task = cast(asyncio.Task, asyncio.current_task()) | ||
task_status.started(task) | ||
try: | ||
await checkpoint() | ||
finally: | ||
await cancel_shielded_checkpoint() | ||
|
||
async with create_task_group() as tg: | ||
task = cast(asyncio.Task, await tg.start(func)) | ||
assert not cancelling(task) | ||
tg.cancel_scope.cancel() | ||
assert cancelling(task) |