diff -r a32ced15b883 Lib/test/test_asyncio/test_events.py --- a/Lib/test/test_asyncio/test_events.py Fri Jun 06 01:27:34 2014 -0500 +++ b/Lib/test/test_asyncio/test_events.py Fri Jun 06 14:17:27 2014 +0200 @@ -1364,6 +1364,18 @@ class EventLoopTestsMixin: with self.assertRaises(RuntimeError): loop.add_writer(w, callback) + def test_read_from_self(self): + # Issue #21595: _read_from_self() should read all pending bytes, not + # only a single byte + def noop(): + pass + # Write 16 bytes into the socket + for i in range(16): + self.loop._write_to_self() + self.loop._read_from_self() + # Ensure that _read_from_self() read all pending bytes + self.assertRaises(BlockingIOError, self.loop._ssock.recv, 4096) + class SubprocessTestsMixin: @@ -1673,6 +1685,21 @@ if sys.platform == 'win32': def test_remove_fds_after_closing(self): raise unittest.SkipTest("IocpEventLoop does not have add_reader()") + + def test_read_from_self(self): + # Issue #21595: _read_from_self() should read all pending bytes, not + # only a single byte + def noop(): + pass + test_utils.run_once(self.loop) + # Write 16 bytes into the socket + for i in range(16): + self.loop._write_to_self() + self.loop.run_until_complete(self.loop._self_reading_future) + # Ensure that _read_from_self() read all pending bytes + self.assertRaises(BlockingIOError, self.loop._ssock.recv, 4096) + + else: from asyncio import selectors