notes: harden external-save test against IO write race
- Commit
a9338875baa343c8613efaf14574959657e49ef7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:23 UTC (28 days ago)
- Parents
549a7cc
externalScreenSaveWritesFileAndAddImports flaked full-suite-only: Save truncates the file on open and saveExternal writes on Dispatchers.IO, which waitForIdle does not cover, so an immediate readText could catch the torn (empty) file. It passed solo and on clean re-runs, confirming a timing flake rather than an app regression; no app code changed. The Save assertion now polls with the file's existing deadline style (up to 8s) instead of a single waitForIdle, so it still fails if the content is genuinely wrong but cannot catch the mid-write truncation window. Verified: full :notes:testDevUnitTest suite green (153 tests, 0 failures).
Diff
notes/src/test/java/com/vayunmathur/notes/ui/NotesPagesTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/ui/NotesPagesTest.kt b/notes/src/test/java/com/vayunmathur/notes/ui/NotesPagesTest.ktindex aae06b7c2b..67b036d9d0 100644--- a/notes/src/test/java/com/vayunmathur/notes/ui/NotesPagesTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/ui/NotesPagesTest.kt@@ -210,7 +210,12 @@ class NotesPagesTest { runCatching { rule.onNodeWithText("external-action").assertIsDisplayed(); true }.getOrDefault(false) } rule.onNodeWithContentDescription("Save").performClick()- rule.waitForIdle()+ // saveExternal writes on Dispatchers.IO, which waitForIdle does not+ // cover; poll so a torn read right after truncation cannot flake this.+ val saveDeadline = System.currentTimeMillis() + 8000+ while (System.currentTimeMillis() < saveDeadline && file.readText() != "original external") {+ Thread.sleep(30); rule.waitForIdle()+ } assertEquals("original external", file.readText()) rule.onNodeWithContentDescription("Add").performClick() val deadline = System.currentTimeMillis() + 8000