feat(profiles): phase 2 — atomic switch coordinator (#824)
* feat(profiles): ProfileSwitchCoordinator — atomic re-home on profile switch (phase 2) * fix(ws): deterministic reconnect backoff in tests (testAutoReconnect flake) * test(ws): harden testAutoReconnect against CI latency (stub token refresh, generous latches) * test(profiles): remove static Dispatchers mock from coordinator test — it bled into HermesWsClientTest in full-suite runs --------- Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
398268d105
commit
531219cdb5
8 files changed
+241
-84
No files matched your search
@@ -907,6 +907,15 @@ class HermesWsClientTest {
|
||||
@Test
|
||||
fun testAutoReconnect() {
|
||||
every { AuthManager.isAutoReconnect() } returns true
|
||||
// Deterministic reconnect: zero backoff removes the real-time race
|
||||
// that flaked this test on loaded CI runners (1s backoff + fixed
|
||||
// 5-6s latch windows routinely overshoot under parallel load).
|
||||
HermesWsClient.setReconnectBackoffForTest(0L)
|
||||
// The reconnect path refreshes the WS token over the network before
|
||||
// opening the socket. Stub it so no real HTTP call sits inside the
|
||||
// test's timing window (CI network latency was the dominant flake).
|
||||
mockkObject(DashboardSessionTokenRefresher)
|
||||
every { DashboardSessionTokenRefresher.fetch(any(), any()) } returns null
|
||||
|
||||
var serverSocket1: WebSocket? = null
|
||||
var serverSocket2: WebSocket? = null
|
||||
@@ -944,8 +953,10 @@ class HermesWsClientTest {
|
||||
|
||||
HermesWsClient.connect()
|
||||
|
||||
assertTrue("Failed initial connection", connect1Latch.await(5, TimeUnit.SECONDS))
|
||||
runBlocking { withTimeout(5000) { HermesWsClient.connectionStatus.first { it == ConnectionStatus.CONNECTED } } }
|
||||
assertTrue("Failed initial connection", connect1Latch.await(15, TimeUnit.SECONDS))
|
||||
runBlocking {
|
||||
withTimeout(15_000) { HermesWsClient.connectionStatus.first { it == ConnectionStatus.CONNECTED } }
|
||||
}
|
||||
assertEquals(ConnectionStatus.CONNECTED, HermesWsClient.connectionStatus.value)
|
||||
|
||||
// Force server to close socket 1 to trigger reconnect
|
||||
@@ -954,13 +965,17 @@ class HermesWsClientTest {
|
||||
// Wait for status to become RECONNECTING
|
||||
runBlocking {
|
||||
withTimeout(
|
||||
5000,
|
||||
15_000,
|
||||
) { HermesWsClient.connectionStatus.first { it == ConnectionStatus.RECONNECTING } }
|
||||
}
|
||||
|
||||
// The client should now attempt to reconnect after initial backoff (1000ms)
|
||||
// Wait for the second connection to hit the server
|
||||
assertTrue("Failed to reconnect", connect2Latch.await(6, TimeUnit.SECONDS))
|
||||
// Wait for the second connection to hit the server. Generous ceiling:
|
||||
// loaded CI runners routinely stretch short wall-clock windows.
|
||||
assertTrue("Failed to reconnect", connect2Latch.await(30, TimeUnit.SECONDS))
|
||||
|
||||
// Restore production backoff so later tests see the default.
|
||||
HermesWsClient.setReconnectBackoffForTest(1_000L)
|
||||
}
|
||||
|
||||
// ── TEST-10: WS reconnect state recovery ────────────────────────────
|
||||
@@ -968,6 +983,9 @@ class HermesWsClientTest {
|
||||
@Test
|
||||
fun testBackoffResetsOnSuccessfulConnect() {
|
||||
every { AuthManager.isAutoReconnect() } returns true
|
||||
// Pin the initial backoff so this test's reset assertion is
|
||||
// deterministic regardless of what earlier tests configured.
|
||||
HermesWsClient.setReconnectBackoffForTest(1_000L)
|
||||
|
||||
val serverLatch = CountDownLatch(1)
|
||||
mockWebServer.enqueue(
|
||||
|
||||
Reference in new issue
Block a user