diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ee5068a43b..9dad0d2877 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,7 @@ jobs: runs-on: ubuntu-22.04 name: Tests strategy: + fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11"] database: [sqlite, postgres] @@ -65,6 +66,12 @@ jobs: - name: Run tests working-directory: ./src run: PRETIX_CONFIG_FILE=tests/travis_${{ matrix.database }}.cfg py.test -n 3 -p no:sugar --cov=./ --cov-report=xml --reruns 3 tests --maxfail=100 + + # XXXXXXXXXXXXXX for test only + - name: print debug output + working-directory: ./src + run: cat /tmp/test.txt + - name: Run concurrency tests working-directory: ./src run: PRETIX_CONFIG_FILE=tests/travis_${{ matrix.database }}.cfg py.test tests/concurrency_tests/ --reruns 0 --reuse-db diff --git a/src/tests/conftest.py b/src/tests/conftest.py index b78b025449..c29bdea927 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -20,8 +20,11 @@ # . # import inspect +import os +import time import pytest +from django.db import connection from django.test import override_settings from django.utils import translation from django_scopes import scopes_disabled @@ -113,3 +116,32 @@ def fakeredis_client(monkeypatch): redis.flushall() monkeypatch.setattr('django_redis.get_redis_connection', get_redis_connection, raising=False) yield redis + + + + +# XXXXXXXXXXXXXXXXXXX for test only + +f = open("/tmp/test.txt","w") + +if os.environ.get("GITHUB_WORKFLOW", ""): + @pytest.fixture(autouse=True) + def ensure_healthy_connection(request, worker_id): + # We have no idea why this is neccessary. It shouldn't be, and it costs some performance. + # However, in ~August 2024 our tests became really flake on GitHub Actions (failing more than 80% of the time) + # for no apparent reason with some error messages related to PostgreSQL connection issues. This appears to + # work around it... + + # Check if the test even has DB access + marker = request.node.get_closest_marker("django_db") + f.write(str(time.time())+"\t"+ str(worker_id)+"\t"+str(request.path)+"\t"+ str(request.module)+"\t"+ str(request.function)+"\tstart\n") + # Run actual test + yield + f.write(str(time.time())+"\t"+ str(worker_id)+"\t"+str(request.path)+"\t"+ str(request.module)+"\t"+ str(request.function)+"\tend\n") + + # If yes, do a dummy query at the end of the test + #if marker: + # with connection.cursor() as cursor: + # cursor.execute("SELECT 1") + +