]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Release app references in AsyncHTTPTestCase tearDown method (#2554)
authorTim Jensen <tim.l.jensen@gmail.com>
Sat, 15 Dec 2018 22:24:03 +0000 (16:24 -0600)
committerBen Darnell <ben@bendarnell.com>
Sat, 15 Dec 2018 22:24:03 +0000 (17:24 -0500)
Releasing the application and HTTP server references in tearDown helps
encourage the GC to clean up resources passed through the application
settings.

tornado/test/testing_test.py
tornado/testing.py

index 49f09a100384673865c060e7fbc4ea27295cdec9..033eaf75178cad884ff7987085f87136cc512f6b 100644 (file)
@@ -172,6 +172,24 @@ class SetUpTearDownTest(unittest.TestCase):
         self.assertEqual(expected, events)
 
 
+class AsyncHTTPTestCaseSetUpTearDownTest(unittest.TestCase):
+    def test_tear_down_releases_app_and_http_server(self):
+        result = unittest.TestResult()
+
+        class SetUpTearDown(AsyncHTTPTestCase):
+            def get_app(self):
+                return Application()
+
+            def test(self):
+                self.assertTrue(hasattr(self, "_app"))
+                self.assertTrue(hasattr(self, "http_server"))
+
+        test = SetUpTearDown("test")
+        test.run(result)
+        self.assertFalse(hasattr(test, "_app"))
+        self.assertFalse(hasattr(test, "http_server"))
+
+
 class GenTest(AsyncTestCase):
     def setUp(self):
         super(GenTest, self).setUp()
index c8ae7712ecaf42d5d3fd6f3085351f47c69ccf31..32c245bc156b7a62a6d5630601b06f5bde02588f 100644 (file)
@@ -432,6 +432,8 @@ class AsyncHTTPTestCase(AsyncTestCase):
             self.http_server.close_all_connections, timeout=get_async_test_timeout()
         )
         self.http_client.close()
+        del self.http_server
+        del self._app
         super(AsyncHTTPTestCase, self).tearDown()