]> granicus.if.org Git - python/commitdiff
[3.7] bpo-33789: Backport test_asyncio fixes from master (GH-7478)
authorVictor Stinner <vstinner@redhat.com>
Thu, 7 Jun 2018 14:19:00 +0000 (16:19 +0200)
committerGitHub <noreply@github.com>
Thu, 7 Jun 2018 14:19:00 +0000 (16:19 +0200)
* bpo-33789: test_asyncio: Fix ResourceWarning (GH-7460)

* Close sockets and streams to fix ResourceWarning warnings
* Catch also OSError to hide a traceback on an expected handshake
  error

(cherry picked from commit 0eba7c39132614a5730cda6b340e18dfb2d30d14)

* bpo-33789, test_asyncio: Hide PendingDeprecationWarning (GH-7461)

Hide PendingDeprecationWarning in test__register_task_3().

(cherry picked from commit 7ed61e9431ee2c191aeeeb26f86a71bb90ab99fd)

* bpo-32676, test_asyncio: Fix warning in test_error_in_call_soon() (GH-7462)

Fix "<CoroWrapper ...> was never yielded from" warning in
PyTask_PyFuture_Tests.test_error_in_call_soon() of
test_asyncio.test_tasks.

Close manually the coroutine on error.

(cherry picked from commit 9f04f0df6fdb27190690bda949d213893d14e807)

Lib/test/test_asyncio/functional.py
Lib/test/test_asyncio/test_sslproto.py
Lib/test/test_asyncio/test_tasks.py

index fbec462c1dbfbd77d188d815a5ad6798a6f3219c..386cfcdb9814f67c490eea71acb948db970763ae 100644 (file)
@@ -150,9 +150,14 @@ class TestSocketWrapper:
             server_hostname=server_hostname,
             do_handshake_on_connect=False)
 
-        ssl_sock.do_handshake()
+        try:
+            ssl_sock.do_handshake()
+        except:
+            ssl_sock.close()
+            raise
+        finally:
+            self.__sock.close()
 
-        self.__sock.close()
         self.__sock = ssl_sock
 
     def __getattr__(self, name):
index 2357130b5f9702c51629e31c802301ee5bf8b9a8..6903fae5f311d3a24b9c667e5f170d82c345e39f 100644 (file)
@@ -600,6 +600,8 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
                     server_side=True)
             except ssl.SSLError:
                 pass
+            except OSError:
+                pass
             finally:
                 sock.close()
 
@@ -636,6 +638,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
             except ssl.SSLError:
                 pass
             finally:
+                orig_sock.close()
                 sock.close()
 
         async def client(addr):
@@ -649,6 +652,8 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
             writer.write(b'B')
             with self.assertRaises(ssl.SSLError):
                 await reader.readline()
+
+            writer.close()
             return 'OK'
 
         with self.tcp_server(server,
index d95c98f0a6179516f96bc24e5d1a89c2aa4ceece..67df3c0f48fde50cc5aa54cb9cc7a131a0d923de 100644 (file)
@@ -2178,7 +2178,11 @@ class BaseTaskTests:
         self.assertFalse(m_log.error.called)
 
         with self.assertRaises(ValueError):
-            self.new_task(self.loop, coro())
+            gen = coro()
+            try:
+                self.new_task(self.loop, gen)
+            finally:
+                gen.close()
 
         self.assertTrue(m_log.error.called)
         message = m_log.error.call_args[0][0]
@@ -2609,7 +2613,8 @@ class BaseTaskIntrospectionTests:
         self.assertEqual(asyncio.all_tasks(loop), set())
         self._register_task(task)
         self.assertEqual(asyncio.all_tasks(loop), set())
-        self.assertEqual(asyncio.Task.all_tasks(loop), {task})
+        with self.assertWarns(PendingDeprecationWarning):
+            self.assertEqual(asyncio.Task.all_tasks(loop), {task})
         self._unregister_task(task)
 
     def test__enter_task(self):