fix: stabilize flaky pre-translation and list handler tests#2114
Open
fix: stabilize flaky pre-translation and list handler tests#2114
Conversation
homeTimelineAcceptsAiSkippedTranslationResult was reading the first emission of the translation flow, but pre-translation runs in a fire-and-forget coroutine that goes through Pending/Translating before reaching Skipped. The test now waits for the Skipped state and cancels its coroutine scope on teardown like neighbouring tests. ListHandlerTest.tearDown now closes the database in a try/finally so stopKoin always runs even if close throws, preventing leaked Koin state from cascading uncaught exceptions into the next test. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The test launched two UNDISPATCHED requests and relied on a single CompletableDeferred to gate them, but the second async could fail to reach the mock handler before the test scheduler advanced. When that happened the deferred was never completed and runTest tripped its dispatch timeout with UncompletedCoroutinesError on CI. Use a pair of deferreds and only start the second request after the first has parked inside the mock, with a withTimeout to fail fast. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The previous attempt still relied on UNDISPATCHED async + sequential deferreds to coordinate the two requests. On iOS the request body did not park inside the mock the way the JVM did, so the first synchronizer never fired and withTimeout(5_000) tripped instead. Drop UNDISPATCHED and the staged deferreds in favour of a single barrier inside the mock handler: the first expired call waits, the second one releases both. This works regardless of dispatcher and guarantees both requests observe the expired token concurrently. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MixedRemoteMediatorTest.homeTimelineAcceptsAiSkippedTranslationResultwas asserting on the first emission from the translation flow, butenqueueStatusesruns in a fire-and-forget coroutine that writesPending/Translatingrows before reachingSkipped. On a slower CI scheduler the test caught an intermediate state and failed. The test now useswithTimeout(5_000) { ... .first { it.status == TranslationStatus.Skipped } }and cancels itscoroutineScopein afinallyblock (matching neighbouring tests) so leftover work cannot leak between tests.ListHandlerTest.tearDownnow closes the database insidetry/finallysostopKoin()always runs even ifdb.close()throws. This prevents leftover Koin state from cascading into aUncaughtExceptionsBeforeTestfailure on the next test (e.g.withDatabaseUpdatesContent).Test plan
./gradlew :shared:jvmTest --tests dev.dimension.flare.data.datasource.microblog.MixedRemoteMediatorTest.homeTimelineAcceptsAiSkippedTranslationResult./gradlew :shared:jvmTest --tests dev.dimension.flare.data.datasource.microblog.handler.ListHandlerTest./gradlew :shared:jvmTest🤖 Generated with Claude Code