mirror of https://github.com/django/django.git
Fixed #32445 -- Fixed LiveServerThreadTest.test_closes_connections() for non-in-memory database on SQLite.
This commit is contained in:
parent
0fd05df7b5
commit
5c4c3e2d1f
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue