1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Made some tests behave nicer re connection handling

This commit is contained in:
Anssi Kääriäinen
2012-11-26 22:52:44 +02:00
parent 905ea9619b
commit 64f6e0370a
2 changed files with 15 additions and 17 deletions

View File

@@ -559,21 +559,27 @@ class ThreadTests(TestCase):
"""
connections_set = set()
connection.cursor()
connections_set.add(connection.connection)
connections_set.add(connection)
def runner():
from django.db import connection
# Passing django.db.connection between threads doesn't work while
# connections[DEFAULT_DB_ALIAS] does.
from django.db import connections
connection = connections[DEFAULT_DB_ALIAS]
connection.cursor()
connections_set.add(connection.connection)
connections_set.add(connection)
for x in range(2):
t = threading.Thread(target=runner)
t.start()
t.join()
self.assertEqual(len(connections_set), 3)
# Check that each created connection got different inner connection.
self.assertEqual(
len(set([conn.connection for conn in connections_set])),
3)
# Finish by closing the connections opened by the other threads (the
# connection opened in the main thread will automatically be closed on
# teardown).
for conn in connections_set:
if conn != connection.connection:
if conn != connection:
conn.close()
def test_connections_thread_local(self):