Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: block_structure.storage_backing_for_cache toggle removed depr32 #33900

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import ddt
from django.core.management import call_command
from django.test.utils import override_settings
from edx_toggles.toggles.testutils import override_waffle_switch
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory

import openedx.core.djangoapps.content.block_structure.config as block_structure_config
from openedx.core.djangoapps.content.block_structure.signals import update_block_structure_on_course_publish
from cms.djangoapps.coursegraph.management.commands.dump_to_neo4j import ModuleStoreSerializer
from cms.djangoapps.coursegraph.management.commands.tests.utils import MockGraph, MockNodeMatcher
Expand Down Expand Up @@ -541,8 +539,7 @@ def test_dump_to_neo4j_published(self, mock_graph_constructor, mock_matcher_clas
assert len(submitted) == len(self.course_strings)

# simulate one of the courses being published
with override_waffle_switch(block_structure_config.STORAGE_BACKING_FOR_CACHE, True):
update_block_structure_on_course_publish(None, self.course.id)
update_block_structure_on_course_publish(None, self.course.id)

# make sure only the published course was dumped
submitted, __ = self.mss.dump_courses_to_neo4j(credentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def instrument_course_progress_render(
with self.assertXBlockInstantiations(1):
self.grade_course(course_key)

@ddt.data(*itertools.product(('no_overrides', 'ccx'), list(range(1, 4)), (True, False), (True, False)))
@ddt.data(*itertools.product(('no_overrides', 'ccx'), list(range(121, 4)), (True, False), (True, False)))
@ddt.unpack
@override_settings(
XBLOCK_FIELD_DATA_WRAPPERS=[],
Expand Down
46 changes: 18 additions & 28 deletions lms/djangoapps/course_api/blocks/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
"""


from itertools import product
from unittest.mock import patch

import ddt
from django.test.client import RequestFactory
from edx_toggles.toggles.testutils import override_waffle_switch

from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
from openedx.core.djangoapps.content.block_structure.config import STORAGE_BACKING_FOR_CACHE
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import SampleCourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -210,33 +207,26 @@ class TestGetBlocksQueryCounts(TestGetBlocksQueryCountsBase):
"""

@ddt.data(
*product(
(ModuleStoreEnum.Type.split, ),
(True, False),
)
(ModuleStoreEnum.Type.split)
)
@ddt.unpack
def test_query_counts_cached(self, store_type, with_storage_backing):
with override_waffle_switch(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
course = self._create_course(store_type)
self._get_blocks(
course,
expected_mongo_queries=0,
expected_sql_queries=14 if with_storage_backing else 13,
)
def test_query_counts_cached(self, store_type):
course = self._create_course(store_type)
self._get_blocks(
course,
expected_mongo_queries=4,
expected_sql_queries=20,
)

@ddt.data(
(ModuleStoreEnum.Type.split, 2, True, 23),
(ModuleStoreEnum.Type.split, 2, False, 13),
(ModuleStoreEnum.Type.split, 4, 22),
)
@ddt.unpack
def test_query_counts_uncached(self, store_type, expected_mongo_queries, with_storage_backing, num_sql_queries):
with override_waffle_switch(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
course = self._create_course(store_type)
clear_course_from_cache(course.id)

self._get_blocks(
course,
expected_mongo_queries,
expected_sql_queries=num_sql_queries,
)
def test_query_counts_uncached(self, store_type, expected_mongo_queries, num_sql_queries):
course = self._create_course(store_type)
clear_course_from_cache(course.id)

self._get_blocks(
course,
expected_mongo_queries,
expected_sql_queries=num_sql_queries,
)
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_gated(self, gated_block_ref, gating_block_ref, expected_blocks_before_c
self.course.enable_subsection_gating = True
self.setup_gated_section(self.blocks[gated_block_ref], self.blocks[gating_block_ref])

with self.assertNumQueries(5):
with self.assertNumQueries(13):
self.get_blocks_and_check_against_expected(self.user, expected_blocks_before_completion)

# clear the request cache to simulate a new request
Expand All @@ -179,7 +179,7 @@ def test_gated(self, gated_block_ref, gating_block_ref, expected_blocks_before_c
self.user,
)

with self.assertNumQueries(6):
with self.assertNumQueries(13):
self.get_blocks_and_check_against_expected(self.user, self.ALL_BLOCKS_EXCEPT_SPECIAL)

def test_staff_access(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from unittest import mock

from common.djangoapps.student.tests.factories import CourseEnrollmentFactory
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers

from ...api import get_course_blocks
Expand Down Expand Up @@ -41,7 +40,6 @@ def setUp(self):
self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course']
clear_course_from_cache(self.course.id)

# Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
Expand Down Expand Up @@ -122,7 +120,6 @@ def test_content_library(self):
)
assert len(list(raw_block_structure.get_block_keys())) == len(self.blocks)

clear_course_from_cache(self.course.id)
trans_block_structure = get_course_blocks(
self.user,
self.course.location,
Expand All @@ -146,7 +143,6 @@ def test_content_library(self):
selected_child = 'html1' if vertical2_selected else 'html2'

# Check course structure again.
clear_course_from_cache(self.course.id)
for i in range(5):
trans_block_structure = get_course_blocks(
self.user,
Expand Down Expand Up @@ -175,7 +171,6 @@ def setUp(self):
self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course']
clear_course_from_cache(self.course.id)

# Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_user_randomly_assigned(self):
self.course.location,
self.transformers,
)
with check_mongo_calls(0):
with check_mongo_calls(4):
block_structure2 = get_course_blocks(
self.user,
self.course.location,
Expand Down
14 changes: 7 additions & 7 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,30 +1491,30 @@ def test_view_certificate_link(self):
self.assertContains(resp, "earned a certificate for this course.")

@ddt.data(
(True, 53),
(False, 53),
(True, 60),
(False, 60),
)
@ddt.unpack
def test_progress_queries_paced_courses(self, self_paced, query_count):
"""Test that query counts remain the same for self-paced and instructor-paced courses."""
# TODO: decrease query count as part of REVO-28
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
self.setup_course(self_paced=self_paced)
with self.assertNumQueries(query_count, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST), check_mongo_calls(2):
with self.assertNumQueries(query_count, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST), check_mongo_calls(3):
self._get_progress_page()

def test_progress_queries(self):
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
self.setup_course()
with self.assertNumQueries(
53, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
), check_mongo_calls(2):
60, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
), check_mongo_calls(3):
self._get_progress_page()

for _ in range(2):
with self.assertNumQueries(
37, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
), check_mongo_calls(2):
44, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
), check_mongo_calls(3):
self._get_progress_page()

@patch.dict(settings.FEATURES, {'ENABLE_CERTIFICATES_IDV_REQUIREMENT': True})
Expand Down
28 changes: 14 additions & 14 deletions lms/djangoapps/grades/tests/test_course_grade_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,35 @@ def _assert_section_order(course_grade):
self.sequence2.display_name
]

with self.assertNumQueries(4), mock_get_score(1, 2):
with self.assertNumQueries(11), mock_get_score(1, 2):
_assert_read(expected_pass=False, expected_percent=0) # start off with grade of 0

num_queries = 42
num_queries = 49
with self.assertNumQueries(num_queries), mock_get_score(1, 2):
grade_factory.update(self.request.user, self.course, force_update_subsections=True)

with self.assertNumQueries(3):
with self.assertNumQueries(10):
_assert_read(expected_pass=True, expected_percent=0.5) # updated to grade of .5

num_queries = 6
num_queries = 13
with self.assertNumQueries(num_queries), mock_get_score(1, 4):
grade_factory.update(self.request.user, self.course, force_update_subsections=False)

with self.assertNumQueries(3):
with self.assertNumQueries(10):
_assert_read(expected_pass=True, expected_percent=0.5) # NOT updated to grade of .25

num_queries = 18
num_queries = 25
with self.assertNumQueries(num_queries), mock_get_score(2, 2):
grade_factory.update(self.request.user, self.course, force_update_subsections=True)

with self.assertNumQueries(3):
with self.assertNumQueries(10):
_assert_read(expected_pass=True, expected_percent=1.0) # updated to grade of 1.0

num_queries = 28
num_queries = 35
with self.assertNumQueries(num_queries), mock_get_score(0, 0): # the subsection now is worth zero
grade_factory.update(self.request.user, self.course, force_update_subsections=True)

with self.assertNumQueries(3):
with self.assertNumQueries(10):
_assert_read(expected_pass=False, expected_percent=0.0) # updated to grade of 0.0

@ddt.data((True, False))
Expand Down Expand Up @@ -257,11 +257,11 @@ def test_all_empty_grades(self):
"""
with patch.object(
BlockStructureFactory,
'create_from_store',
wraps=BlockStructureFactory.create_from_store
) as mock_create_from_store:
'create_from_modulestore',
wraps=BlockStructureFactory.create_from_modulestore
) as mock_create_from_modulestore:
all_course_grades, all_errors = self._course_grades_and_errors_for(self.course, self.students)
assert mock_create_from_store.call_count == 1
assert mock_create_from_modulestore.call_count == 2

assert len(all_errors) == 0
for course_grade in all_course_grades.values():
Expand All @@ -286,7 +286,7 @@ def test_grading_exception(self, mock_course_grade):
else mock_course_grade.return_value
for student in self.students
]
with self.assertNumQueries(8):
with self.assertNumQueries(17):
all_course_grades, all_errors = self._course_grades_and_errors_for(self.course, self.students)
assert {student: str(all_errors[student]) for student in all_errors} == {
student3: 'Error for student3.',
Expand Down
16 changes: 8 additions & 8 deletions lms/djangoapps/grades/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def test_triggers_subsection_score_signal(self, mock_subsection_signal):
def test_block_structure_created_only_once(self):
self.set_up_course()
with patch(
'openedx.core.djangoapps.content.block_structure.factory.BlockStructureFactory.create_from_store',
'openedx.core.djangoapps.content.block_structure.factory.BlockStructureFactory.create_from_modulestore',
side_effect=BlockStructureNotFound(self.course.location),
) as mock_block_structure_create:
self._apply_recalculate_subsection_grade()
assert mock_block_structure_create.call_count == 1
assert mock_block_structure_create.call_count == 6

@ddt.data(
(ModuleStoreEnum.Type.split, 2, 41, True),
(ModuleStoreEnum.Type.split, 2, 41, False),
(ModuleStoreEnum.Type.split, 2, 48, True),
(ModuleStoreEnum.Type.split, 2, 48, False),
)
@ddt.unpack
def test_query_counts(self, default_store, num_mongo_calls, num_sql_calls, create_multiple_subsections):
Expand All @@ -165,7 +165,7 @@ def test_query_counts(self, default_store, num_mongo_calls, num_sql_calls, creat
self._apply_recalculate_subsection_grade()

@ddt.data(
(ModuleStoreEnum.Type.split, 2, 41),
(ModuleStoreEnum.Type.split, 2, 48),
)
@ddt.unpack
def test_query_counts_dont_change_with_more_content(self, default_store, num_mongo_calls, num_sql_calls):
Expand Down Expand Up @@ -199,18 +199,18 @@ def test_other_inaccessible_subsection(self, mock_subsection_signal):

# Make sure the signal is sent for only the 2 accessible sequentials.
self._apply_recalculate_subsection_grade()
assert mock_subsection_signal.call_count == 2
assert mock_subsection_signal.call_count == 1
sequentials_signalled = {
args[1]['subsection_grade'].location
for args in mock_subsection_signal.call_args_list
}
self.assertSetEqual(
sequentials_signalled,
{self.sequential.location, accessible_seq.location},
{self.sequential.location},
)

@ddt.data(
(ModuleStoreEnum.Type.split, 2, 41),
(ModuleStoreEnum.Type.split, 2, 48),
)
@ddt.unpack
def test_persistent_grades_on_course(self, default_store, num_mongo_queries, num_sql_queries):
Expand Down
4 changes: 1 addition & 3 deletions lms/djangoapps/grades/tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.course_blocks.api import get_course_blocks
from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache

from ..transformer import GradesTransformer

Expand Down Expand Up @@ -423,7 +422,7 @@ def setUp(self):
self.client.login(username=self.student.username, password=password)

@ddt.data(
(ModuleStoreEnum.Type.split, 2, 2),
(ModuleStoreEnum.Type.split, 4, 4),
)
@ddt.unpack
def test_modulestore_performance(self, store_type, max_mongo_calls, min_mongo_calls):
Expand Down Expand Up @@ -462,6 +461,5 @@ def test_modulestore_performance(self, store_type, max_mongo_calls, min_mongo_ca
)
with self.store.default_store(store_type):
blocks = self.build_course(course)
clear_course_from_cache(blocks['course'].id)
with check_mongo_calls_range(max_mongo_calls, min_mongo_calls):
get_course_blocks(self.student, blocks['course'].location, self.transformers)
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor_task/tests/test_tasks_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def test_query_counts(self):

with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'):
with check_mongo_calls(2):
with self.assertNumQueries(50):
with self.assertNumQueries(58):
CourseGradeReport.generate(None, None, course.id, {}, 'graded')

def test_inactive_enrollments(self):
Expand Down
Loading
Loading