Skip to content

Commit ab04eb5

Browse files
committed
Revert 3d235b7
1 parent 97b3681 commit ab04eb5

File tree

2 files changed

+1
-65
lines changed

2 files changed

+1
-65
lines changed

async_timeout/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ def _do_exit(self, exc_type: Type[BaseException]) -> None:
207207
return None
208208

209209
def _on_timeout(self, task: "asyncio.Task[None]") -> None:
210-
# See Issue #229 and PR #230 for details
211-
if task._fut_waiter and task._fut_waiter.cancelled(): # type: ignore[attr-defined] # noqa: E501
212-
return
213210
task.cancel()
214211
self._state = _State.TIMEOUT
215212

tests/test_timeout.py

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import asyncio
2-
import sys
32
import time
43
from functools import wraps
54
from typing import Any, Callable, List, TypeVar
65

76
import pytest
87

9-
from async_timeout import Timeout, timeout, timeout_at
8+
from async_timeout import timeout, timeout_at
109

1110

1211
_Func = TypeVar("_Func", bound=Callable[..., Any])
@@ -359,63 +358,3 @@ async def test_deprecated_with() -> None:
359358
with pytest.warns(DeprecationWarning):
360359
with timeout(1):
361360
await asyncio.sleep(0)
362-
363-
364-
async def race_condition(offset: float = 0) -> List[str]:
365-
"""Common code for below race condition tests."""
366-
367-
async def test_task(deadline: float, loop: asyncio.AbstractEventLoop) -> None:
368-
# We need the internal Timeout class to specify the deadline (not delay).
369-
# This is needed to create the precise timing to reproduce the race condition.
370-
with pytest.warns(DeprecationWarning):
371-
with Timeout(deadline, loop):
372-
await asyncio.sleep(10)
373-
374-
call_order: List[str] = []
375-
f_exit = log_func(Timeout._do_exit, "exit", call_order)
376-
Timeout._do_exit = f_exit # type: ignore[assignment]
377-
f_timeout = log_func(Timeout._on_timeout, "timeout", call_order)
378-
Timeout._on_timeout = f_timeout # type: ignore[assignment]
379-
380-
loop = asyncio.get_running_loop()
381-
deadline = loop.time() + 1
382-
t = asyncio.create_task(test_task(deadline, loop))
383-
loop.call_at(deadline + offset, log_func(t.cancel, "cancel", call_order))
384-
# If we get a TimeoutError, then the code is broken.
385-
with pytest.raises(asyncio.CancelledError):
386-
await t
387-
388-
return call_order
389-
390-
391-
@pytest.mark.skipif(sys.version_info < (3, 7), reason="Not supported in 3.6")
392-
@pytest.mark.asyncio
393-
async def test_race_condition_cancel_before() -> None:
394-
"""Test race condition when cancelling before timeout.
395-
396-
If cancel happens immediately before the timeout, then
397-
the timeout may overrule the cancellation, making it
398-
impossible to cancel some tasks.
399-
"""
400-
call_order = await race_condition()
401-
402-
# This test is very timing dependant, so we check the order that calls
403-
# happened to be sure the test itself ran correctly.
404-
assert call_order == ["cancel", "timeout", "exit"]
405-
406-
407-
@pytest.mark.xfail(reason="Can't see a way to fix this currently.")
408-
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Can't be fixed in <3.9.")
409-
@pytest.mark.asyncio
410-
async def test_race_condition_cancel_after() -> None:
411-
"""Test race condition when cancelling after timeout.
412-
413-
Similarly to the previous test, if a cancel happens
414-
immediately after the timeout (but before the __exit__),
415-
then the explicit cancel can get overruled again.
416-
"""
417-
call_order = await race_condition(0.000001)
418-
419-
# This test is very timing dependant, so we check the order that calls
420-
# happened to be sure the test itself ran correctly.
421-
assert call_order == ["timeout", "cancel", "exit"]

0 commit comments

Comments
 (0)