From 3754bd219aefd78e140d1699564f9da854447a68 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Mon, 1 Nov 2021 16:42:46 -0400 Subject: [PATCH] fix: force reset of modulestore data for test cases In #8bdf59b, the SplitModuleStore was given a Django ORM backed store for active version data (i.e. "which version is currently published?"). This started to cause sporadic test failures depending on the test ordering, such as this module: openedx/features/course_experience/tests/views/test_course_home.py The root cause was that the database table holding these active versions was not being properly cleared after tests, probably because of the odd ordering we do MongoDB vs. Django ORM data initialization in the ModuleStoreTestCase and SharedModuleStoreTestCase classes. This is an overly broad hammer fix for this, because: 1. The obvious thing to add it into the ModuleStoreIsolationMixin didn't seem to work. 2. While overly broad, it's a small bit of code and should be safe. 3. It's more urgent to fix this flakiness in the build (affecting maybe 1/4 test runs?) ASAP, rather than tracking this down. --- .../xmodule/modulestore/tests/django_utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 3b23e1b83e..717618413d 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -19,6 +19,7 @@ from django.test.utils import override_settings from lms.djangoapps.courseware.field_overrides import OverrideFieldData from openedx.core.djangolib.testing.utils import CacheIsolationMixin, CacheIsolationTestCase, FilteredQueryCountMixin from openedx.core.lib.tempdir import mkdtemp_clean +from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import AdminFactory, UserFactory, InstructorFactory from common.djangoapps.student.tests.factories import StaffFactory @@ -28,7 +29,6 @@ from xmodule.modulestore.django import SignalHandler, clear_existing_modulestore from xmodule.modulestore.tests.factories import XMODULE_FACTORY_LOCK from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM - class CourseUserType(Enum): """ Types of users to be used when testing a course. @@ -470,6 +470,12 @@ class SharedModuleStoreTestCase( cls.end_modulestore_isolation() super().tearDownClass() + # Overly broad hammer that breaks abstraction barrier to clear data from + # the table underlying the Django ORM backed modulestore active versions + # lookup. This has to go _after_ the super().tearDownClass call above, + # or it doesn't work. + SplitModulestoreCourseIndex.objects.all().delete() + def setUp(self): # OverrideFieldData.provider_classes is always reset to `None` so # that they're recalculated for every test @@ -530,6 +536,12 @@ class ModuleStoreTestCase( def tearDownClass(cls): super().tearDownClass() + # Overly broad hammer that breaks abstraction barrier to clear data from + # the table underlying the Django ORM backed modulestore active versions + # lookup. This has to go _after_ the super().tearDownClass call above, + # or it doesn't work. + SplitModulestoreCourseIndex.objects.all().delete() + def setUp(self): """ Creates a test User if `self.CREATE_USER` is True.