Skip to content

Flaky tests fix 2#1044

Closed
franco-zalamena-iterable wants to merge 14 commits intomasterfrom
flaky-tests-fix-2
Closed

Flaky tests fix 2#1044
franco-zalamena-iterable wants to merge 14 commits intomasterfrom
flaky-tests-fix-2

Conversation

@franco-zalamena-iterable
Copy link
Copy Markdown
Contributor

Test

franco-zalamena-iterable and others added 14 commits April 1, 2026 17:35
These tests use @RunWith(JUnit4) with only org.json imports and have
no Android framework dependencies. Running them as JVM unit tests
removes the emulator requirement and speeds up CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace Mockito.timeout() with shadowOf(getMainLooper()).idle() +
  verify() in IterablePushRegistrationTaskTest and IterableInAppManagerTest
- Replace Thread.sleep(1000) with shadowOf(getMainLooper()).idle() in
  IterableNotificationTest

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update 23 @ignore annotations with actionable descriptions:
- JWT tests: blocked on IterableAuthManager.executor not being injectable
- Universal link test: needs MockWebServer to stub HTTP redirect
- Database logout test: IterableTaskStorage singleton state leakage
- In-app stalling tests: Robolectric incompatible, need Espresso

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
testSyncOnLogin: initialize() can trigger syncInApp via background init,
causing a double call. Reset the mock after initialize so the verify
only checks the setEmail-triggered sync.

testTrackPushOpenWithCustomAction: cross-test state leakage causes a
spurious inApp/getMessages request that arrives at the mock server before
trackPushOpen. Skip non-trackPushOpen requests when verifying.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ests

Cross-test state leakage causes spurious inApp/getMessages requests to
arrive at the mock server before the expected requests. Added a helper
takeRequestWithPath() that skips unexpected in-app sync requests when
verifying request order.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
testSetEmailWithAutomaticPushRegistration / testSetUserIdWithAutomaticPushRegistration:
initialize() can trigger executePushRegistrationTask via background init.
Reset the mock after initialize so verify only captures the setEmail/setUserId call.

testMessagePersistentReadStateFromServer: Flush pending looper callbacks
from setUp's createIterableApiNew before the test starts. Stale
onPostExecute callbacks can corrupt InlineExecutorService state under
CI resource pressure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…n delete

The createIterableApiNew() call triggers syncInApp() via setEmail(), which
consumes the single enqueued MockWebServer response meant for the test.
Fix by enqueuing a dummy response for the init-triggered sync, plus flushing
the looper before test assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
setUp's createIterableApiNew() fires async HTTP requests (InAppManager
constructor sync + setEmail sync) on background threads. On CI, these
can arrive at MockWebServer after a test enqueues its responses,
consuming them. Fix by:

1. Draining all setUp HTTP requests via server.takeRequest() in setUp
2. Flushing their looper callbacks with idle()
3. Adding idle() to testJsonOnlyInAppMessageDelegateCallbacks to flush
   the constructor sync before foreground transition

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The tests raced initializeInBackground() against setEmail/setUserId —
if background init completed before the API calls, operations executed
immediately instead of being queued, failing the size assertion.

Fix: use simulateInitializingState() to hold init in progress, then
simulateInitializationComplete() after assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- testSetEmailWithAutomaticPushRegistration: flush looper before resetting
  the mock so background init callbacks don't trigger extra push registration
- IterableAsyncInitializationTest: increase all waitForAsyncInitialization
  timeouts from 3s to 5s for CI reliability

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove simulateInitializationComplete() from PII masking tests that
only verify queue contents. The call triggers processAll() ->
shutdownBackgroundExecutorAsync() which can race with the next test's
executor setup, causing testInitializeInBackground_WithConfig to fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
shutdownBackgroundExecutorAsync() now captures the executor reference
before spawning the shutdown thread, so it only shuts down the intended
executor — not a replacement created by resetBackgroundInitializationState().

resetBackgroundInitializationState() now always creates a fresh executor
instead of conditionally reusing one that may have a pending async shutdown.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@franco-zalamena-iterable franco-zalamena-iterable deleted the flaky-tests-fix-2 branch April 9, 2026 09:53
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.

1 participant