office: make OfficeViewModelSyncSlice3Test deterministic in CI
- Commit
762cad8329f9f3b62797767693d7d98ee187515e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 13:55 UTC (29 days ago)
- Parents
32acdfe
Install a failing OfficeSync.httpTransport (the seam landed on main) in setUp and restore it in tearDown, so the share registration error and the syncDoc cursor assertions exercise the production offline branches deterministically even on a CI box with internet, where the real relay used to answer and flip both assertions. Verified: targeted classes 3x (--no-build-cache) and the full :office:testDevUnitTest suite (953 tests) pass. (cherry picked from commit a78d51942b99040064fb6cc0a0fe37deb63fa920)
Diff
office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt
diff --git a/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt b/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.ktindex a91f589584..ecce5cd5bd 100644--- a/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt+++ b/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt@@ -36,10 +36,10 @@ import org.mockito.Mockito.`when` * Slice 3/4: SyncA/B/C ViewModel helpers with no real network. * * A test PQC identity is installed on [OfficeSync] so signing/sealing runs- * for real; every server call fails fast on DNS (devserver has no route to- * the relay), so the production code's offline/null-result branches are the- * behaviour under test. DataStore-backed helpers are driven against either- * the real Robolectric store or a map-backed mock.+ * for real; [OfficeSync.httpTransport] is replaced with a failing double so no+ * test touches the real relay, and the production code's offline/null-result+ * branches are the behaviour under test. DataStore-backed helpers are driven+ * against either the real Robolectric store or a map-backed mock. */ @org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class) @OptIn(ExperimentalCoroutinesApi::class)@@ -57,8 +57,14 @@ class OfficeViewModelSyncSlice3Test { private val roboApp: android.app.Application get() = ApplicationProvider.getApplicationContext() + private var previousTransport: OfficeSync.HttpTransport? = null+ @BeforeTest fun setUp() {+ // Never touch the real relay: every POST fails as if offline, so the+ // production offline branches are exercised deterministically in CI too.+ previousTransport = OfficeSync.httpTransport+ OfficeSync.httpTransport = OfficeSync.HttpTransport { _, _ -> null } Dispatchers.setMain(UnconfinedTestDispatcher()) runBlocking { if (runCatching { OfficeSync.identity }.isFailure) {@@ -69,6 +75,7 @@ class OfficeViewModelSyncSlice3Test { @AfterTest fun tearDown() {+ OfficeSync.httpTransport = previousTransport OfficeSync.stopLive() Dispatchers.resetMain() }