Gate Android polling behind realtime health
This commit is contained in:
@@ -62,7 +62,7 @@ test("android realtime client always clears the active connection after stream s
|
||||
|
||||
assert.match(
|
||||
source,
|
||||
/try\s*\{[\s\S]{0,1200}int statusCode = connection\.getResponseCode\(\);[\s\S]{0,220}throw new IOException\("REALTIME_STREAM_HTTP_" \+ statusCode\);[\s\S]{0,2000}finally\s*\{\s*activeConnection = null;\s*connection\.disconnect\(\);\s*\}/,
|
||||
/try\s*\{[\s\S]{0,1200}int statusCode = connection\.getResponseCode\(\);[\s\S]{0,220}throw new IOException\("REALTIME_STREAM_HTTP_" \+ statusCode\);[\s\S]{0,2000}finally\s*\{[\s\S]{0,160}activeConnection = null;\s*connection\.disconnect\(\);\s*\}/,
|
||||
"expected non-2xx SSE setup failures to still flow through the connection cleanup finally block",
|
||||
);
|
||||
});
|
||||
|
||||
51
tests/android-realtime-fallback-polling.test.ts
Normal file
51
tests/android-realtime-fallback-polling.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
async function readSource(path: string) {
|
||||
return readFile(new URL(path, import.meta.url), "utf8");
|
||||
}
|
||||
|
||||
test("BossRealtimeClient tracks whether the SSE stream is currently connected", async () => {
|
||||
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/BossRealtimeClient.java");
|
||||
|
||||
assert.match(source, /private volatile boolean connected;/, "expected realtime client to cache connection state");
|
||||
assert.match(source, /boolean isConnected\(\)\s*\{\s*return connected;\s*\}/, "expected realtime client to expose connection state");
|
||||
assert.match(source, /connected = true;/, "expected realtime client to flip connected once the SSE stream is ready");
|
||||
assert.match(source, /connected = false;/, "expected realtime client to clear connected when the stream stops");
|
||||
});
|
||||
|
||||
test("MainActivity only performs conversation polling when realtime is unavailable", async () => {
|
||||
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/MainActivity.java");
|
||||
|
||||
assert.match(
|
||||
source,
|
||||
/private boolean shouldAutoRefreshConversations\(\)\s*\{[\s\S]{0,240}!isRealtimeConnected\(\)/,
|
||||
"expected root conversation polling to back off while realtime is healthy",
|
||||
);
|
||||
assert.match(
|
||||
source,
|
||||
/private boolean shouldMaintainConversationAutoRefresh\(\)/,
|
||||
"expected root page to keep a lightweight fallback scheduler even when polling is paused",
|
||||
);
|
||||
});
|
||||
|
||||
test("ProjectDetailActivity keeps a fallback poller for chat pages when realtime disconnects", async () => {
|
||||
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ProjectDetailActivity.java");
|
||||
|
||||
assert.match(
|
||||
source,
|
||||
/private static final long CONVERSATION_AUTO_REFRESH_MS = [\d_]+L;/,
|
||||
"expected chat detail page to define a fallback polling cadence",
|
||||
);
|
||||
assert.match(
|
||||
source,
|
||||
/private boolean shouldAutoRefreshConversation\(\)\s*\{[\s\S]{0,260}!isRealtimeConnected\(\)/,
|
||||
"expected chat detail fallback polling to only run when realtime is disconnected",
|
||||
);
|
||||
assert.match(
|
||||
source,
|
||||
/conversationAutoRefreshRunnable/,
|
||||
"expected chat detail page to own an auto-refresh runnable for fallback polling",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user