mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #22414 -- Ensured that LiveServerTestCase closes connections.
This commit is contained in:
committed by
Tim Graham
parent
7b08e01c13
commit
f6cd669ff2
28
tests/servers/test_liveserverthread.py
Normal file
28
tests/servers/test_liveserverthread.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user