|
1 | 1 | import asyncio |
2 | | -import sys |
3 | 2 | import time |
4 | 3 | from functools import wraps |
5 | 4 | from typing import Any, Callable, List, TypeVar |
6 | 5 |
|
7 | 6 | import pytest |
8 | 7 |
|
9 | | -from async_timeout import Timeout, timeout, timeout_at |
| 8 | +from async_timeout import timeout, timeout_at |
10 | 9 |
|
11 | 10 |
|
12 | 11 | _Func = TypeVar("_Func", bound=Callable[..., Any]) |
@@ -359,63 +358,3 @@ async def test_deprecated_with() -> None: |
359 | 358 | with pytest.warns(DeprecationWarning): |
360 | 359 | with timeout(1): |
361 | 360 | 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