mirror of
https://github.com/django/django.git
synced 2025-04-25 09:44:36 +00:00
Made DatabaseWrapper thread sharing logic reentrant. Used a reference counting like scheme to allow nested uses. The error appeared after 8c775391b78b2a4a2b57c5e89ed4888f36aada4b. Backport of 76990cbbda5d93fda560c8a5ab019860f7efaab7 from master.
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
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}
|
|
|
|
conn.inc_thread_sharing()
|
|
try:
|
|
self.assertTrue(conn.is_usable())
|
|
self.run_live_server_thread(connections_override)
|
|
self.assertFalse(conn.is_usable())
|
|
finally:
|
|
conn.dec_thread_sharing()
|