Skip to content

Fix integration test event races (onReady, onSyncDone) - #159

Merged
nicolas-chaix-didomi merged 4 commits into
mainfrom
fix/integration-test-onready-race
Aug 5, 2026
Merged

Fix integration test event races (onReady, onSyncDone)#159
nicolas-chaix-didomi merged 4 commits into
mainfrom
fix/integration-test-onready-race

Conversation

@nicolas-chaix-didomi

@nicolas-chaix-didomi nicolas-chaix-didomi commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Two related races in the integration test helpers, both causing intermittent CI failures on Android. No production code touched — integration tests only.

1. onReadyInitializeHelper.initialize

InitializeHelper.initialize only waited on DidomiSdk.isReady (method channel). The event channel dispatches onReady slightly later, so tests that assert on their own listener-backed isReady flag immediately after the helper returns could race the event.

  • InitializeHelper.initialize takes an optional isReady getter. After the method-channel check it keeps polling the caller's flag until it flips true (sharing the existing 20s timeout), then asserts it with a clear failure reason.
  • Passed as isReady: () => isReady from every call site so the flag is re-read on each poll rather than captured by value.

2. onSyncDonewaitForSync

CI still failed after the above, at set_user_with_id_test.dart:282 (syncDoneUserId == userId). That is a separate race, in a helper the first commit did not touch.

waitForSync polled only on syncReadyEvent, but callers assert on syncDoneUserId immediately after it returns. onSyncReady and onSyncDone are dispatched as separate events with no ordering guarantee, so the helper could return while syncDoneUserId was still null from the preceding resetExpectedSyncValues().

  • The loop now waits for both fields, in set_user_with_id_test.dart, set_user_with_hash_test.dart and set_user_with_encryption_test.dart.
  • Added a 20s bound (syncTimeout in util/constants.dart) so a lost event fails the test rather than spinning until the suite-level timeout.
  • Paths ending in assert(syncError == true) are unaffected: syncDoneUserId legitimately stays null there, and the existing !syncError term still ends the loop.

Verification

flutter analyze integration_test is clean. These are timing races needing an emulator, so a single local run would not prove much either way — CI over a couple of runs is the real check.

Not addressed

  • vendor_status_listener_test.dart and initialize_with_success_test.dart still call InitializeHelper.initialize without isReady:. Both pass today, but they are the remaining files not covered by the first fix.
  • The three waitForSync copies remain duplicated across test files. Worth hoisting into util/, but that is a wider refactor than this fix.

The method channel reports readiness before the event channel has
dispatched onReady, so tests asserting on a listener-backed isReady flag
right after InitializeHelper.initialize could race the event.

Add an optional isReady getter to InitializeHelper.initialize that polls
the caller's flag (within the existing 20s timeout) and asserts it became
true, and pass it from every call site.
waitForSync only polled on syncReadyEvent, but callers assert on
syncDoneUserId right after it returns. onSyncReady and onSyncDone are
dispatched as separate events with no ordering guarantee, so the helper
could return while syncDoneUserId was still null, failing assertions
such as set_user_with_id_test.dart:282 intermittently on CI.

Also bound the wait with a 20s timeout so a lost event ends the test
instead of spinning until the suite-level timeout.

Paths ending in onSyncError are unaffected: syncDoneUserId legitimately
stays null there, and the existing !syncError term still ends the loop.
@nicolas-chaix-didomi nicolas-chaix-didomi changed the title Wait for onReady event in integration test initialize helper Fix integration test event races (onReady, onSyncDone) Aug 4, 2026
Comment thread example/integration_test/util/constants.dart Outdated
Comment thread example/integration_test/consent_state_test.dart Outdated
…eIfNeeded

Removes the duplicated `if (!isReady) { InitializeHelper.initialize(...) }`
block from every integration test in favor of a single helper method, per
review feedback on PR #159.
@nicolas-chaix-didomi
nicolas-chaix-didomi merged commit d9bbf5c into main Aug 5, 2026
9 of 10 checks passed
@nicolas-chaix-didomi
nicolas-chaix-didomi deleted the fix/integration-test-onready-race branch August 5, 2026 14:48
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.

2 participants