Refs #32416 -- Added LiveServerTestCase._make_connections_override() hook.

This commit is contained in:
Chris Jerdonek 2021-04-12 08:41:39 +02:00 committed by Mariusz Felisiak
parent e4430f22c8
commit 71a936f9d8
1 changed files with 11 additions and 4 deletions

View File

@ -1553,21 +1553,28 @@ class LiveServerTestCase(TransactionTestCase):
return cls.host return cls.host
@classmethod @classmethod
def setUpClass(cls): def _make_connections_override(cls):
super().setUpClass()
connections_override = {} connections_override = {}
for conn in connections.all(): for conn in connections.all():
# If using in-memory sqlite databases, pass the connections to # If using in-memory sqlite databases, pass the connections to
# the server thread. # the server thread.
if conn.vendor == 'sqlite' and conn.is_in_memory_db(): if conn.vendor == 'sqlite' and conn.is_in_memory_db():
# Explicitly enable thread-shareability for this connection
conn.inc_thread_sharing()
connections_override[conn.alias] = conn connections_override[conn.alias] = conn
return connections_override
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._live_server_modified_settings = modify_settings( cls._live_server_modified_settings = modify_settings(
ALLOWED_HOSTS={'append': cls.allowed_host}, ALLOWED_HOSTS={'append': cls.allowed_host},
) )
cls._live_server_modified_settings.enable() cls._live_server_modified_settings.enable()
connections_override = cls._make_connections_override()
for conn in connections_override.values():
# Explicitly enable thread-shareability for this connection.
conn.inc_thread_sharing()
cls.server_thread = cls._create_server_thread(connections_override) cls.server_thread = cls._create_server_thread(connections_override)
cls.server_thread.daemon = True cls.server_thread.daemon = True
cls.server_thread.start() cls.server_thread.start()