Commit 09dc884c by Calen Pennington

Isolate databases between test processes

parent cb2ac424
...@@ -57,6 +57,10 @@ NOSE_ARGS = [ ...@@ -57,6 +57,10 @@ NOSE_ARGS = [
'--xunit-file', _REPORT_DIR / 'nosetests.xml', '--xunit-file', _REPORT_DIR / 'nosetests.xml',
] ]
NOSE_PLUGINS = [
'openedx.core.djangolib.testing.utils.NoseDatabaseIsolation'
]
TEST_ROOT = path('test_root') TEST_ROOT = path('test_root')
# Want static files in the same dir for running on jenkins. # Want static files in the same dir for running on jenkins.
......
...@@ -99,6 +99,10 @@ NOSE_ARGS = [ ...@@ -99,6 +99,10 @@ NOSE_ARGS = [
'--xunit-file', _REPORT_DIR / 'nosetests.xml', '--xunit-file', _REPORT_DIR / 'nosetests.xml',
] ]
NOSE_PLUGINS = [
'openedx.core.djangolib.testing.utils.NoseDatabaseIsolation'
]
# Local Directories # Local Directories
TEST_ROOT = path("test_root") TEST_ROOT = path("test_root")
# Want static files in the same dir for running on jenkins. # Want static files in the same dir for running on jenkins.
...@@ -181,12 +185,10 @@ CONTENTSTORE = { ...@@ -181,12 +185,10 @@ CONTENTSTORE = {
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': TEST_ROOT / 'db' / 'edx.db',
'ATOMIC_REQUESTS': True, 'ATOMIC_REQUESTS': True,
}, },
'student_module_history': { 'student_module_history': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': TEST_ROOT / 'db' / 'student_module_history.db'
}, },
} }
......
...@@ -10,11 +10,14 @@ Utility classes for testing django applications. ...@@ -10,11 +10,14 @@ Utility classes for testing django applications.
import copy import copy
from django import db
from django.core.cache import caches from django.core.cache import caches
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from django.conf import settings from django.conf import settings
from django.contrib import sites from django.contrib import sites
from nose.plugins import Plugin
from request_cache.middleware import RequestCache from request_cache.middleware import RequestCache
...@@ -138,3 +141,20 @@ class CacheIsolationTestCase(CacheIsolationMixin, TestCase): ...@@ -138,3 +141,20 @@ class CacheIsolationTestCase(CacheIsolationMixin, TestCase):
self.clear_caches() self.clear_caches()
self.addCleanup(self.clear_caches) self.addCleanup(self.clear_caches)
class NoseDatabaseIsolation(Plugin):
"""
nosetest plugin that resets django databases before any tests begin.
Used to make sure that tests running in multi processes aren't sharing
a database connection.
"""
name = "database-isolation"
def begin(self):
"""
Before any tests start, reset all django database connections.
"""
for db_ in db.connections.all():
db_.close()
...@@ -97,21 +97,22 @@ case "$TEST_SUITE" in ...@@ -97,21 +97,22 @@ case "$TEST_SUITE" in
;; ;;
"lms-unit") "lms-unit")
LMS_ARGS="--with-flaky"
case "$SHARD" in case "$SHARD" in
"all") "all")
paver test_system -s lms --extra_args="--with-flaky" --cov_args="-p" paver test_system -s lms --extra_args="$LMS_ARGS" --cov_args="-p" -v
;; ;;
"1") "1")
paver test_system -s lms --extra_args="--attr='shard_1' --with-flaky" --cov_args="-p" -v paver test_system -s lms --extra_args="--attr='shard_1' $LMS_ARGS" --cov_args="-p" -v
;; ;;
"2") "2")
paver test_system -s lms --extra_args="--attr='shard_2' --with-flaky" --cov_args="-p" -v paver test_system -s lms --extra_args="--attr='shard_2' $LMS_ARGS" --cov_args="-p" -v
;; ;;
"3") "3")
paver test_system -s lms --extra_args="--attr='shard_3' --with-flaky" --cov_args="-p" -v paver test_system -s lms --extra_args="--attr='shard_3' $LMS_ARGS" --cov_args="-p" -v
;; ;;
"4") "4")
paver test_system -s lms --extra_args="--attr='shard_1=False,shard_2=False,shard_3=False' --with-flaky" --cov_args="-p" -v paver test_system -s lms --extra_args="--attr='shard_1=False,shard_2=False,shard_3=False' $LMS_ARGS" --cov_args="-p" -v
;; ;;
*) *)
# If no shard is specified, rather than running all tests, create an empty xunit file. This is a # If no shard is specified, rather than running all tests, create an empty xunit file. This is a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment