euicc: deflake startDownload state tests (105 tests)
- Commit
24ad0c62ab2ceebcbd21bf712c4729cc40056b23- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-15 03:23 UTC (21 days ago)
- Parents
339f027
EuiccViewModelTest failed in the loaded full check with 'expected Preparing was Failed'. startDownload assigns DownloadState.Preparing synchronously and then launches the authenticate on IO; with Dispatchers.Main set to Unconfined in the test, that IO failure can complete and move the state to the terminal Failed before the test thread manages to read the transient Preparing - under load the thread scheduling gap is exactly what widens. Preparing is a pass-through state with no minimum dwell, so asserting it exactly races the failure it precedes. The test now asserts the download has left Idle (Preparing or already Failed) immediately after each startDownload call and then awaits the terminal Failed state through a shared awaitFailed helper, for both the initial attempt and the retry from Failed. The guarantees actually under test - a download with no channel fails cleanly with a null message, and Failed is a re-entry point - are asserted exactly as before. Verified: before, the failure appeared in the loaded 128-worker full check while isolated reruns passed (3/3 isolated baseline runs green with --no-build-cache). After: 5 consecutive green :euicc:testDevUnitTest runs, 3 isolated at --max-workers=32 and 2 under load at --max-workers=64 on a busy host (105 tests).
Diff
euicc/src/test/java/com/vayunmathur/euicc/platform/EuiccViewModelTest.kt
diff --git a/euicc/src/test/java/com/vayunmathur/euicc/platform/EuiccViewModelTest.kt b/euicc/src/test/java/com/vayunmathur/euicc/platform/EuiccViewModelTest.ktindex 1efb391dc6..55fa8bc969 100644--- a/euicc/src/test/java/com/vayunmathur/euicc/platform/EuiccViewModelTest.kt+++ b/euicc/src/test/java/com/vayunmathur/euicc/platform/EuiccViewModelTest.kt@@ -56,21 +56,36 @@ class EuiccViewModelTest { } } + /** Awaits the terminal Failed state of a download started with no channel. */+ private fun awaitFailed(vm: EuiccViewModel) {+ val deadline = System.currentTimeMillis() + 10_000+ while (vm.download !is DownloadState.Failed && System.currentTimeMillis() < deadline) Thread.sleep(10)+ assertTrue(vm.download is DownloadState.Failed, "download=${vm.download}")+ }+ @Test fun `startDownload fails cleanly without channel and can be retried from Failed`() { val vm = vm() awaitSettled(vm) vm.startDownload("LPA:1\$smdp.example.com\$MATCH1", imei = "123", confirmationCode = null)- assertEquals(DownloadState.Preparing, vm.download)- val deadline = System.currentTimeMillis() + 10_000- while (vm.download !is DownloadState.Failed && System.currentTimeMillis() < deadline) Thread.sleep(10)- assertTrue(vm.download is DownloadState.Failed, "download=${vm.download}")+ // Preparing is set synchronously, but the IO authenticate that+ // fails it runs concurrently: under load the terminal Failed can+ // land before the test thread reads the transient state, so+ // asserting Preparing exactly races the failure it precedes.+ // Assert the flow left Idle (Preparing or already Failed), then+ // await the terminal state.+ assertTrue(+ vm.download is DownloadState.Preparing || vm.download is DownloadState.Failed,+ "download=${vm.download}",+ )+ awaitFailed(vm) assertNull((vm.download as DownloadState.Failed).message) // Failed is a re-entry point. vm.startDownload("LPA:1\$smdp.example.com\$MATCH1")- assertEquals(DownloadState.Preparing, vm.download)- val deadline2 = System.currentTimeMillis() + 10_000- while (vm.download !is DownloadState.Failed && System.currentTimeMillis() < deadline2) Thread.sleep(10)- assertTrue(vm.download is DownloadState.Failed)+ assertTrue(+ vm.download is DownloadState.Preparing || vm.download is DownloadState.Failed,+ "download=${vm.download}",+ )+ awaitFailed(vm) } @Test fun `confirm submit cancel and clear are no-ops without pending session`() {