mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
asyncio: sync with Tulip
* PipeServer.close() now cancels the "accept pipe" future which cancels the overlapped operation. * Fix _SelectorTransport.__repr__() if the transport was closed * Fix debug log in BaseEventLoop.create_connection(): get the socket object from the transport because SSL transport closes the old socket and creates a new SSL socket object. Remove also the _SelectorSslTransport._rawsock attribute: it contained the closed socket (not very useful) and it was not used. * Issue #22063: socket operations (sock_recv, sock_sendall, sock_connect, sock_accept) of the proactor event loop don't raise an exception in debug mode if the socket are in blocking mode. Overlapped operations also work on blocking sockets. * Fix unit tests in debug mode: mock a non-blocking socket for socket operations which now raise an exception if the socket is blocking. * _fatal_error() method of _UnixReadPipeTransport and _UnixWritePipeTransport now log all exceptions in debug mode * Don't log expected errors in unit tests * Tulip issue 200: _WaitHandleFuture._unregister_wait() now catchs and logs exceptions. * Tulip issue 200: Log errors in debug mode instead of simply ignoring them.
This commit is contained in:
parent
d71dcbb043
commit
b261475a48
10 changed files with 120 additions and 64 deletions
|
@ -58,8 +58,9 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
self.loop.remove_reader = mock.Mock()
|
||||
self.loop.remove_writer = mock.Mock()
|
||||
waiter = asyncio.Future(loop=self.loop)
|
||||
transport = self.loop._make_ssl_transport(
|
||||
m, asyncio.Protocol(), m, waiter)
|
||||
with test_utils.disable_logger():
|
||||
transport = self.loop._make_ssl_transport(
|
||||
m, asyncio.Protocol(), m, waiter)
|
||||
self.assertIsInstance(transport, _SelectorSslTransport)
|
||||
|
||||
@mock.patch('asyncio.selector_events.ssl', None)
|
||||
|
@ -127,7 +128,8 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
|
||||
def test_write_to_self_tryagain(self):
|
||||
self.loop._csock.send.side_effect = BlockingIOError
|
||||
self.assertIsNone(self.loop._write_to_self())
|
||||
with test_utils.disable_logger():
|
||||
self.assertIsNone(self.loop._write_to_self())
|
||||
|
||||
def test_write_to_self_exception(self):
|
||||
# _write_to_self() swallows OSError
|
||||
|
@ -135,7 +137,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
self.assertRaises(RuntimeError, self.loop._write_to_self)
|
||||
|
||||
def test_sock_recv(self):
|
||||
sock = mock.Mock()
|
||||
sock = test_utils.mock_nonblocking_socket()
|
||||
self.loop._sock_recv = mock.Mock()
|
||||
|
||||
f = self.loop.sock_recv(sock, 1024)
|
||||
|
@ -183,7 +185,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
self.assertIs(err, f.exception())
|
||||
|
||||
def test_sock_sendall(self):
|
||||
sock = mock.Mock()
|
||||
sock = test_utils.mock_nonblocking_socket()
|
||||
self.loop._sock_sendall = mock.Mock()
|
||||
|
||||
f = self.loop.sock_sendall(sock, b'data')
|
||||
|
@ -193,7 +195,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
self.loop._sock_sendall.call_args[0])
|
||||
|
||||
def test_sock_sendall_nodata(self):
|
||||
sock = mock.Mock()
|
||||
sock = test_utils.mock_nonblocking_socket()
|
||||
self.loop._sock_sendall = mock.Mock()
|
||||
|
||||
f = self.loop.sock_sendall(sock, b'')
|
||||
|
@ -295,7 +297,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
self.loop.add_writer.call_args[0])
|
||||
|
||||
def test_sock_connect(self):
|
||||
sock = mock.Mock()
|
||||
sock = test_utils.mock_nonblocking_socket()
|
||||
self.loop._sock_connect = mock.Mock()
|
||||
|
||||
f = self.loop.sock_connect(sock, ('127.0.0.1', 8080))
|
||||
|
@ -361,7 +363,7 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
self.assertIsInstance(f.exception(), OSError)
|
||||
|
||||
def test_sock_accept(self):
|
||||
sock = mock.Mock()
|
||||
sock = test_utils.mock_nonblocking_socket()
|
||||
self.loop._sock_accept = mock.Mock()
|
||||
|
||||
f = self.loop.sock_accept(sock)
|
||||
|
@ -782,7 +784,8 @@ class SelectorSocketTransportTests(test_utils.TestCase):
|
|||
transport = _SelectorSocketTransport(
|
||||
self.loop, self.sock, self.protocol)
|
||||
transport._force_close = mock.Mock()
|
||||
transport._read_ready()
|
||||
with test_utils.disable_logger():
|
||||
transport._read_ready()
|
||||
transport._force_close.assert_called_with(err)
|
||||
|
||||
@mock.patch('logging.exception')
|
||||
|
@ -1219,7 +1222,8 @@ class SelectorSslTransportTests(test_utils.TestCase):
|
|||
err = self.sslsock.recv.side_effect = ConnectionResetError()
|
||||
transport = self._make_one()
|
||||
transport._force_close = mock.Mock()
|
||||
transport._read_ready()
|
||||
with test_utils.disable_logger():
|
||||
transport._read_ready()
|
||||
transport._force_close.assert_called_with(err)
|
||||
|
||||
def test_read_ready_recv_retry(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue