]> granicus.if.org Git - python/commitdiff
bpo-33789: test_asyncio: Fix ResourceWarning (GH-7460)
authorVictor Stinner <vstinner@redhat.com>
Wed, 6 Jun 2018 23:12:38 +0000 (01:12 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Jun 2018 23:12:38 +0000 (01:12 +0200)
* Close sockets and streams to fix ResourceWarning warnings
* Catch also OSError to hide a traceback on an expected handshake
  error

Lib/test/test_asyncio/functional.py
Lib/test/test_asyncio/test_sslproto.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 d02d441a8309cd2855e980307c6cf59b22875f0c..78ab1eb8223148f2c147cbb3174a87cd1539fbdc 100644 (file)
@@ -604,6 +604,8 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
                     server_side=True)
             except ssl.SSLError:
                 pass
+            except OSError:
+                pass
             finally:
                 sock.close()
 
@@ -640,6 +642,7 @@ class BaseStartTLS(func_tests.FunctionalTestCaseMixin):
             except ssl.SSLError:
                 pass
             finally:
+                orig_sock.close()
                 sock.close()
 
         async def client(addr):
@@ -653,6 +656,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,