From 569996d30a200a2338b84131a4aa4b83448ce473 Mon Sep 17 00:00:00 2001 From: Razvan Mahu Date: Wed, 30 Mar 2022 12:19:58 +0100 Subject: [PATCH] fix: use a non threaded server in SeleniumTestCase --- game/end_to_end_tests/selenium_test_case.py | 21 ++++++++++++++++++++- rapid_router_test_settings.py | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/game/end_to_end_tests/selenium_test_case.py b/game/end_to_end_tests/selenium_test_case.py index 4fb202022..7fc3234ff 100644 --- a/game/end_to_end_tests/selenium_test_case.py +++ b/game/end_to_end_tests/selenium_test_case.py @@ -6,7 +6,26 @@ see more information here: https://github.com/jazzband/django-pipeline/issues/593 """ -from django.contrib.staticfiles.testing import LiveServerTestCase +from django.core.servers.basehttp import WSGIServer +from django.test.testcases import ( + LiveServerTestCase, + LiveServerThread, + QuietWSGIRequestHandler, +) from django_selenium_clean import SeleniumTestCase + +class NonThreadedLiveServerThread(LiveServerThread): + """ + Replaces ThreadedWSGIServer with WSGIServer as the threaded one doesn't close the DB connections properly, thus + triggering random "DB table locked" errors. + """ + + def _create_server(self): + return WSGIServer( + (self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False + ) + + SeleniumTestCase.__bases__ = (LiveServerTestCase,) +SeleniumTestCase.server_thread_class = NonThreadedLiveServerThread diff --git a/rapid_router_test_settings.py b/rapid_router_test_settings.py index 8f5bda1bb..fdcd4eab7 100644 --- a/rapid_router_test_settings.py +++ b/rapid_router_test_settings.py @@ -7,7 +7,7 @@ SELENIUM_WEBDRIVERS = { "default": {"callable": webdriver.Chrome, "args": (), "kwargs": {}}, - "chrome": {"callable": webdriver.Firefox, "args": (), "kwargs": {}}, + "firefox": {"callable": webdriver.Firefox, "args": (), "kwargs": {}}, "chrome-headless": { "callable": webdriver.Chrome, "args": (),