Skip to content

test: fix flaky tests caused by multithreaded tests #1334

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

Merged
merged 3 commits into from
Jun 5, 2025
Merged
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
20 changes: 18 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,27 @@ jobs:
- name: Check migrations are up to date
run: poetry run /usr/bin/env aap-eda-manage makemigrations --dry-run --check

- name: Run tests
- name: Run default tests
run: |
poetry run python -m pytest -vv --cov=./ --cov-report=xml --junit-xml=eda-server-test-results.xml
poetry run python -m pytest -vv \
--cov=./ \
--cov-report=xml \
--junit-xml=eda-server-default.xml
echo "GIT_SHA=$(git rev-parse "$GITHUB_SHA")" >> "$GITHUB_ENV"

- name: Run multithreaded tests
run: |
poetry run python -m pytest -vv \
--cov=./ \
--cov-append \
--junit-xml=eda-server-multithreaded.xml \
-m "multithreaded"

- name: Merge test results
run: |
pip install junitparser
junitparser merge eda-server-default.xml eda-server-multithreaded.xml eda-server-test-results.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
Expand Down
1 change: 1 addition & 0 deletions Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tasks:
$ task test -- tests/integration/api/test_activation.py::test_retrieve_activation
cmds:
- "{{.PYTEST_CMD}} {{.CLI_ARGS}}"
- "{{.PYTEST_CMD}} -m multithreaded {{.CLI_ARGS}}"

lint:
desc: "Run all linters."
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ env =
EDA_MODE=development
DJANGO_SETTINGS_MODULE = aap_eda.settings.default
log_file_level = INFO
markers =
multithreaded # mark multithreaded tests, these tests must be run in a separate process

15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
from aap_eda.settings import redis as redis_settings


#################################################################
# run tests setup
#################################################################
def pytest_runtest_setup(item):
marker_expr = item.config.getoption("-m")

if "multithreaded" in item.keywords and (
not marker_expr or "multithreaded" not in marker_expr
):
pytest.skip(
"Skipped multithreaded test "
"(not explicitly selected via `-m multithreaded`)"
)


#################################################################
# Log capture factory
#################################################################
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_advisory_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
],
)
@pytest.mark.django_db
@pytest.mark.multithreaded
def test_job_uniqueness(module_data):
call_log = []
lock = Lock()
Expand Down
Loading