summaryrefslogtreecommitdiff
path: root/tests/servers
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2021-02-20 19:23:56 -0800
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-23 06:08:43 +0100
commit5c4c3e2d1f232df6de24741ca1df32442a01ebc3 (patch)
treebb2f347db4fe4d913c6c93b0f36893175cde2989 /tests/servers
parent0fd05df7b5690fb1b675e1b4d9c92bb22ff74360 (diff)
downloaddjango-5c4c3e2d1f232df6de24741ca1df32442a01ebc3.tar.gz
Fixed #32445 -- Fixed LiveServerThreadTest.test_closes_connections() for non-in-memory database on SQLite.
Diffstat (limited to 'tests/servers')
-rw-r--r--tests/servers/test_liveserverthread.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/servers/test_liveserverthread.py b/tests/servers/test_liveserverthread.py
index 8dc213137a..09b6ca08c8 100644
--- a/tests/servers/test_liveserverthread.py
+++ b/tests/servers/test_liveserverthread.py
@@ -1,9 +1,14 @@
from django.db import DEFAULT_DB_ALIAS, connections
-from django.test import LiveServerTestCase, TestCase
+from django.test import LiveServerTestCase, TransactionTestCase
from django.test.testcases import LiveServerThread
-class LiveServerThreadTest(TestCase):
+# Use TransactionTestCase instead of TestCase to run outside of a transaction,
+# otherwise closing the connection would implicitly rollback and not set the
+# connection to None.
+class LiveServerThreadTest(TransactionTestCase):
+
+ available_apps = []
def run_live_server_thread(self, connections_override=None):
thread = LiveServerTestCase._create_server_thread(connections_override)
@@ -16,12 +21,13 @@ class LiveServerThreadTest(TestCase):
conn = connections[DEFAULT_DB_ALIAS]
# Pass a connection to the thread to check they are being closed.
connections_override = {DEFAULT_DB_ALIAS: conn}
-
+ # Open a connection to the database.
+ conn.connect()
conn.inc_thread_sharing()
try:
- self.assertTrue(conn.is_usable())
+ self.assertIsNotNone(conn.connection)
self.run_live_server_thread(connections_override)
- self.assertFalse(conn.is_usable())
+ self.assertIsNone(conn.connection)
finally:
conn.dec_thread_sharing()