diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-01-26 14:04:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-01-26 14:04:03 (GMT) |
commit | e0fd157ba0cc92e435e7520b4ff641ca68d72244 (patch) | |
tree | 413608ff4152b0b250869964ccb9dd0280cacea8 /Lib/test | |
parent | 2a3f38fd299c09be89a7872ccd15c4aedd5fc145 (diff) | |
download | cpython-e0fd157ba0cc92e435e7520b4ff641ca68d72244.zip cpython-e0fd157ba0cc92e435e7520b4ff641ca68d72244.tar.gz cpython-e0fd157ba0cc92e435e7520b4ff641ca68d72244.tar.bz2 |
Issue #23293, asyncio: Rewrite IocpProactor.connect_pipe() as a coroutine
Use a coroutine with asyncio.sleep() instead of call_later() to ensure that the
schedule call is cancelled.
Add also a unit test cancelling connect_pipe().
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncio/test_windows_events.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index f9b3dd1..73d8fcd 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -1,6 +1,7 @@ import os import sys import unittest +from unittest import mock if sys.platform != 'win32': raise unittest.SkipTest('Windows only') @@ -91,6 +92,18 @@ class ProactorTests(test_utils.TestCase): return 'done' + def test_connect_pipe_cancel(self): + exc = OSError() + exc.winerror = _overlapped.ERROR_PIPE_BUSY + with mock.patch.object(_overlapped, 'ConnectPipe', side_effect=exc) as connect: + coro = self.loop._proactor.connect_pipe('pipe_address') + task = self.loop.create_task(coro) + + # check that it's possible to cancel connect_pipe() + task.cancel() + with self.assertRaises(asyncio.CancelledError): + self.loop.run_until_complete(task) + def test_wait_for_handle(self): event = _overlapped.CreateEvent(None, True, False, None) self.addCleanup(_winapi.CloseHandle, event) |