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

[DO NOT MERGE] test PR for debugging slow tests #1126

Closed
wants to merge 18 commits 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
2 changes: 1 addition & 1 deletion .github/workflows/run-docker-compose-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Run tests
run: |
docker compose exec django pytest -v
s/pr-check



2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
# PostgreSQL with PostGIS extension
postgis:
<<: *global # this will inherit config from x-global-environment
image: postgis/postgis:15-3.3
image: postgis/postgis:16-3.5
volumes:
- postgis-data:/var/lib/postgresql/data
restart: always
Expand Down
4 changes: 4 additions & 0 deletions epilepsy12/common_view_functions/aggregate_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ def update_kpi_aggregation_model(

return

print(f"!! kpi_value_counts query !!")
print(f"!! {kpi_value_counts.query} !!")
print(f"!! {kpi_value_counts.explain(analyze=True, buffers=True)}")

# update models where numbers have changed.
for value_count in kpi_value_counts:
ABSTRACTION_CODE = value_count.pop(f"organisation__{abstraction_level.value}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _register_cases_in_organisation(


def _register_kpi_scored_cases(
e12_case_factory, ods_codes: "list[str]", num_cases: int = 10
e12_case_factory, ods_codes: "list[str]", num_cases: int = 10, debug_create_cases: bool = True
):
"""Helper function to return a queryset of num_cases kids with scored, known KPI scores.

Expand Down Expand Up @@ -89,13 +89,14 @@ def _register_kpi_scored_cases(
ineligible_answers,
incomplete_answers,
]:
test_cases = e12_case_factory.create_batch(
num_cases,
organisations__organisation=organisation,
first_name=f"temp_{organisation.name}",
**answer_set,
)
filled_case_objects += test_cases
if debug_create_cases:
test_cases = e12_case_factory.create_batch(
num_cases,
organisations__organisation=organisation,
first_name=f"temp_{organisation.name}",
**answer_set,
)
filled_case_objects += test_cases

for test_case in filled_case_objects:
test_case.registration.completed_first_year_of_care_date = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_calculate_kpi_value_counts_queryset_all_levels(
]
else 10
),
debug_create_cases=True,
)

for code in ods_codes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# 3rd party imports
from django.apps import apps
from django.db import connection

# E12 imports
from epilepsy12.common_view_functions import (
Expand All @@ -21,6 +22,17 @@
from .helpers import _clean_cases_from_test_db, _register_kpi_scored_cases


@pytest.fixture
def disable_presorted_aggregate_in_db(db):
# pass
cursor = connection.cursor()
print("!! Disabling presorted aggregate in DB")
cursor.execute("SET enable_presorted_aggregate TO off")
yield
print("!! Re-enabling presorted aggregate in DB")
cursor.execute("SET enable_presorted_aggregate TO on")


@pytest.mark.parametrize(
"abstraction_level, abstraction_codes, ods_codes",
[
Expand Down Expand Up @@ -68,7 +80,7 @@
)
@pytest.mark.django_db
def test_update_kpi_aggregation_model_all_levels(
abstraction_level, abstraction_codes, ods_codes, e12_case_factory
abstraction_level, abstraction_codes, ods_codes, e12_case_factory, disable_presorted_aggregate_in_db
):
"""Testing the `update_kpi_aggregation_model` fn.

Expand Down
6 changes: 6 additions & 0 deletions s/pr-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

# s/test

s/test -s epilepsy12/tests/common_view_functions_tests/aggregate_by_tests/test_calculate_kpi_value_counts_queryset.py \
epilepsy12/tests/common_view_functions_tests/aggregate_by_tests/test_update_kpiaggregation_model.py
Loading