From: Tim Jensen Date: Sat, 15 Dec 2018 22:24:03 +0000 (-0600) Subject: Release app references in AsyncHTTPTestCase tearDown method (#2554) X-Git-Tag: v6.0.0b1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaad182ae6b1a00f20fe3f15c7d454109c42f6ec;p=thirdparty%2Ftornado.git Release app references in AsyncHTTPTestCase tearDown method (#2554) Releasing the application and HTTP server references in tearDown helps encourage the GC to clean up resources passed through the application settings. --- diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index 49f09a100..033eaf751 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -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() diff --git a/tornado/testing.py b/tornado/testing.py index c8ae7712e..32c245bc1 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -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()