diff options
| author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2016-08-19 09:47:41 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-19 12:47:41 -0400 |
| commit | f6cd669ff203192c29495174e53da6b16883b039 (patch) | |
| tree | 60a16de6590c6ee18e67470b49afab16b071d0f2 /tests/servers/test_liveserverthread.py | |
| parent | 7b08e01c1358aedbd46fa26c91d4613d642ff609 (diff) | |
Fixed #22414 -- Ensured that LiveServerTestCase closes connections.
Diffstat (limited to 'tests/servers/test_liveserverthread.py')
| -rw-r--r-- | tests/servers/test_liveserverthread.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/servers/test_liveserverthread.py b/tests/servers/test_liveserverthread.py new file mode 100644 index 0000000000..d39aac8183 --- /dev/null +++ b/tests/servers/test_liveserverthread.py @@ -0,0 +1,28 @@ +from django.db import DEFAULT_DB_ALIAS, connections +from django.test import LiveServerTestCase, TestCase + + +class LiveServerThreadTest(TestCase): + + def run_live_server_thread(self, connections_override=None): + thread = LiveServerTestCase._create_server_thread(connections_override) + thread.daemon = True + thread.start() + thread.is_ready.wait() + thread.terminate() + + def test_closes_connections(self): + conn = connections[DEFAULT_DB_ALIAS] + if conn.vendor == 'sqlite' and conn.is_in_memory_db(): + self.skipTest("the sqlite backend's close() method is a no-op when using an in-memory database") + # Pass a connection to the thread to check they are being closed. + connections_override = {DEFAULT_DB_ALIAS: conn} + + saved_sharing = conn.allow_thread_sharing + try: + conn.allow_thread_sharing = True + self.assertTrue(conn.is_usable()) + self.run_live_server_thread(connections_override) + self.assertFalse(conn.is_usable()) + finally: + conn.allow_thread_sharing = saved_sharing |
