Skip to content

test: fix flaky AuditIntegrationTest await conditions [DHIS2-21858]#24502

Merged
netroms merged 1 commit into
masterfrom
DHIS2-21858-flaky-audit-test
Jul 21, 2026
Merged

test: fix flaky AuditIntegrationTest await conditions [DHIS2-21858]#24502
netroms merged 1 commit into
masterfrom
DHIS2-21858-flaky-audit-test

Conversation

@netroms

@netroms netroms commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Problem

AuditIntegrationTest regularly fails PR CI, e.g. testSaveRoute(AuthScheme)[3] expected 1 audit but was 0, [4] expected 1 but was 2 (example run).

Two bugs:

  1. All seven await conditions used countAudits(query) >= 0, which is vacuously true - the tests never waited for the async Artemis audit consumer and raced it (was 0).
  2. testSaveRoute reused the shared BASE_UID for every AuthScheme parameter run. Audit rows are written outside the test transaction and not rolled back, so a late audit from a previous run leaked into the next run's query (was 2).

Fix

Await countAudits(query) >= 1 and use a unique CodeGenerator.generateUid() per parameterized run.

Verification

mvn test -pl dhis-test-integration -Dtest=AuditIntegrationTest (Testcontainers Postgres): 10/10 pass.

AI Assisted

The await conditions used countAudits(query) >= 0 which is vacuously
true, so the tests never actually waited for the async Artemis audit
consumer and raced it instead (expected 1 audit but was 0).

testSaveRoute additionally reused the shared BASE_UID for every
AuthScheme parameter run. Audit rows are written outside the test
transaction and are not rolled back, so a late audit from a previous
run leaked into the next run's query (expected 1 but was 2).

Await >= 1 and use a unique UID per parameterized run.

AI Assisted
@sonarqubecloud

Copy link
Copy Markdown

@netroms
netroms merged commit dbf909d into master Jul 21, 2026
23 checks passed
@netroms
netroms deleted the DHIS2-21858-flaky-audit-test branch July 21, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants