[2.2.x] Fixed #30171 -- Fixed DatabaseError in servers tests.

Made DatabaseWrapper thread sharing logic reentrant. Used a reference
counting like scheme to allow nested uses.

The error appeared after 8c775391b7.
Backport of 76990cbbda from master.
This commit is contained in:
Jon Dufresne 2019-02-14 07:04:55 -08:00 committed by Tim Graham
parent 07b44a251a
commit 37cc6a9dce
7 changed files with 100 additions and 66 deletions

View file

@ -18,11 +18,10 @@ class LiveServerThreadTest(TestCase):
# Pass a connection to the thread to check they are being closed.
connections_override = {DEFAULT_DB_ALIAS: conn}
saved_sharing = conn.allow_thread_sharing
conn.inc_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
conn.dec_thread_sharing()