From aaad182ae6b1a00f20fe3f15c7d454109c42f6ec Mon Sep 17 00:00:00 2001 From: Tim Jensen Date: Sat, 15 Dec 2018 16:24:03 -0600 Subject: [PATCH] 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. --- tornado/test/testing_test.py | 18 ++++++++++++++++++ tornado/testing.py | 2 ++ 2 files changed, 20 insertions(+) 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() -- 2.47.2