summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_unix_events.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-03 22:11:52 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-03 22:11:52 (GMT)
commit223a624158254e2c907116a756f6ffe63c49fb7a (patch)
treec777076d19ecb165b487e1e6b0fd2b95d71b37b2 /Lib/test/test_asyncio/test_unix_events.py
parentb9b965f6dd5be211a9ce047ac00070e51bc9b7a8 (diff)
downloadcpython-223a624158254e2c907116a756f6ffe63c49fb7a.zip
cpython-223a624158254e2c907116a756f6ffe63c49fb7a.tar.gz
cpython-223a624158254e2c907116a756f6ffe63c49fb7a.tar.bz2
Issue #21119: asyncio now closes sockets on errors
Fix ResourceWarning: create_connection(), create_datagram_endpoint() and create_unix_server() methods of event loop now close the newly created socket on error.
Diffstat (limited to 'Lib/test/test_asyncio/test_unix_events.py')
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 744c319..cec7a11 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -256,6 +256,24 @@ class SelectorEventLoopUnixSocketTests(unittest.TestCase):
'A UNIX Domain Socket was expected'):
self.loop.run_until_complete(coro)
+ @mock.patch('asyncio.unix_events.socket')
+ def test_create_unix_server_bind_error(self, m_socket):
+ # Ensure that the socket is closed on any bind error
+ sock = mock.Mock()
+ m_socket.socket.return_value = sock
+
+ sock.bind.side_effect = OSError
+ coro = self.loop.create_unix_server(lambda: None, path="/test")
+ with self.assertRaises(OSError):
+ self.loop.run_until_complete(coro)
+ self.assertTrue(sock.close.called)
+
+ sock.bind.side_effect = MemoryError
+ coro = self.loop.create_unix_server(lambda: None, path="/test")
+ with self.assertRaises(MemoryError):
+ self.loop.run_until_complete(coro)
+ self.assertTrue(sock.close.called)
+
def test_create_unix_connection_path_sock(self):
coro = self.loop.create_unix_connection(
lambda: None, '/dev/null', sock=object())