69 lines
2.4 KiB
TypeScript
69 lines
2.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
|
|
const realtimeClientSourceUrl = new URL(
|
|
"../android/app/src/main/java/com/hyzq/boss/BossRealtimeClient.java",
|
|
import.meta.url,
|
|
);
|
|
|
|
async function readRealtimeClientSource() {
|
|
return readFile(realtimeClientSourceUrl, "utf8");
|
|
}
|
|
|
|
test("android realtime client restores session when the SSE stream returns 401", async () => {
|
|
const source = await readRealtimeClientSource();
|
|
|
|
assert.match(
|
|
source,
|
|
/REALTIME_STREAM_HTTP_401/,
|
|
"expected realtime client to classify 401 stream failures explicitly",
|
|
);
|
|
assert.match(
|
|
source,
|
|
/catch\s*\(Exception\s+\w+\)\s*\{[\s\S]{0,800}apiClient\.restoreSession\(\)/,
|
|
"expected realtime loop to attempt restoreSession before falling back to blind retry",
|
|
);
|
|
});
|
|
|
|
test("android realtime client does not wait a full minute before reconnecting a silent stream", async () => {
|
|
const source = await readRealtimeClientSource();
|
|
|
|
assert.doesNotMatch(
|
|
source,
|
|
/setReadTimeout\(60_000\)/,
|
|
"a 60s SSE read timeout makes message delivery feel stale after transient network stalls",
|
|
);
|
|
assert.match(
|
|
source,
|
|
/STREAM_READ_TIMEOUT_MS\s*=\s*(25_000|30_000|35_000)/,
|
|
"expected the SSE read timeout budget to stay close to the server keepalive window",
|
|
);
|
|
assert.match(
|
|
source,
|
|
/setReadTimeout\(STREAM_READ_TIMEOUT_MS\)/,
|
|
"expected the realtime stream to apply the tighter read timeout budget",
|
|
);
|
|
});
|
|
|
|
test("android realtime client emits connection logs for reconnect debugging", async () => {
|
|
const source = await readRealtimeClientSource();
|
|
|
|
assert.match(source, /android\.util\.Log/, "expected realtime client to import Android logging");
|
|
assert.match(
|
|
source,
|
|
/Log\.(i|w|e)\(TAG,\s*"/,
|
|
"expected realtime client to log connection state changes for field debugging",
|
|
);
|
|
});
|
|
|
|
test("android realtime client always clears the active connection after stream setup failures", async () => {
|
|
const source = await readRealtimeClientSource();
|
|
|
|
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\S]{0,160}activeConnection = null;\s*connection\.disconnect\(\);\s*\}/,
|
|
"expected non-2xx SSE setup failures to still flow through the connection cleanup finally block",
|
|
);
|
|
});
|