summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2017-10-26 18:48:55 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2018-03-12 13:27:27 (GMT)
commitf1af12e6a1b66b62332d0d981c9534727e80b6de (patch)
tree3e7d807735bc8c3afb7366dd92d1b9853ad819c8
parentbe791d54a89d302e39258a2cc8321494f8a60e03 (diff)
downloaddjango-mellon-f1af12e6a1b66b62332d0d981c9534727e80b6de.zip
django-mellon-f1af12e6a1b66b62332d0d981c9534727e80b6de.tar.gz
django-mellon-f1af12e6a1b66b62332d0d981c9534727e80b6de.tar.bz2
tests: prevent "Database is locked" error during concurrency test (fixes #19678)
SQLite has a default timeout of 5 seconds, we augment it to 400 seconds. We also replace our custom thread pool by the one provided by multiprocessing.
-rw-r--r--tests/test_default_adapter.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/tests/test_default_adapter.py b/tests/test_default_adapter.py
index 8189a39..9214781 100644
--- a/tests/test_default_adapter.py
+++ b/tests/test_default_adapter.py
@@ -1,7 +1,7 @@
-import threading
import pytest
import re
import lasso
+from multiprocessing.pool import ThreadPool
from django.contrib import auth
from django.db import connection
@@ -57,20 +57,19 @@ def test_lookup_user(settings):
def test_lookup_user_transaction(transactional_db, concurrency):
adapter = DefaultAdapter()
-
- def map_threads(f, l):
- threads = []
- for i in l:
- threads.append(threading.Thread(target=f, args=(i,)))
- threads[-1].start()
- for thread in threads:
- thread.join()
- users = []
+ p = ThreadPool(concurrency)
def f(i):
- users.append(adapter.lookup_user(idp, saml_attributes))
- connection.close()
- map_threads(f, range(concurrency))
+ # sqlite has a default lock timeout of 5s seconds between different access to the same in
+ # memory DB
+ if connection.vendor == 'sqlite':
+ connection.cursor().execute('PRAGMA busy_timeout = 400000')
+ try:
+ return adapter.lookup_user(idp, saml_attributes)
+ finally:
+ connection.close()
+ users = p.map(f, range(concurrency))
+
assert len(users) == concurrency
assert len(set(user.pk for user in users)) == 1