summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorBen Darnell <ben@bendarnell.com>2020-08-31 19:57:52 (GMT)
committerGitHub <noreply@github.com>2020-08-31 19:57:52 (GMT)
commitea5a6363c3f8cc90b7c0cc573922b10f296073b6 (patch)
tree9464334a7c5d9f0b5dc76a227b915a9850d05c90 /Lib/test/test_asyncio
parentc3a651ad2544d7d1be389b63e9a4a58a92a31623 (diff)
downloadcpython-ea5a6363c3f8cc90b7c0cc573922b10f296073b6.zip
cpython-ea5a6363c3f8cc90b7c0cc573922b10f296073b6.tar.gz
cpython-ea5a6363c3f8cc90b7c0cc573922b10f296073b6.tar.bz2
bpo-39010: Fix errors logged on proactor loop restart (#22017)
Stopping and restarting a proactor event loop on windows can lead to spurious errors logged (ConnectionResetError while reading from the self pipe). This fixes the issue by ensuring that we don't attempt to start multiple copies of the self-pipe reading loop.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_proactor_events.py1
-rw-r--r--Lib/test/test_asyncio/test_windows_events.py20
2 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index d0ab387..4c8906d 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -753,6 +753,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
def test_loop_self_reading_fut(self):
fut = mock.Mock()
+ self.loop._self_reading_future = fut
self.loop._loop_self_reading(fut)
self.assertTrue(fut.result.called)
self.proactor.recv.assert_called_with(self.ssock, 4096)
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 6b00570..33388a8 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -211,6 +211,26 @@ class ProactorTests(test_utils.TestCase):
fut.cancel()
fut.cancel()
+ def test_read_self_pipe_restart(self):
+ # Regression test for https://bugs.python.org/issue39010
+ # Previously, restarting a proactor event loop in certain states
+ # would lead to spurious ConnectionResetErrors being logged.
+ self.loop.call_exception_handler = mock.Mock()
+ # Start an operation in another thread so that the self-pipe is used.
+ # This is theoretically timing-dependent (the task in the executor
+ # must complete before our start/stop cycles), but in practice it
+ # seems to work every time.
+ f = self.loop.run_in_executor(None, lambda: None)
+ self.loop.stop()
+ self.loop.run_forever()
+ self.loop.stop()
+ self.loop.run_forever()
+ # If we don't wait for f to complete here, we may get another
+ # warning logged about a thread that didn't shut down cleanly.
+ self.loop.run_until_complete(f)
+ self.loop.close()
+ self.assertFalse(self.loop.call_exception_handler.called)
+
class WinPolicyTests(test_utils.TestCase):