Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(desktop): tighten stream 401 retry test assertions (#82914)

Charles Vienba5c449e6d2c
diff --git a/products/desktop/packages/core/src/cloud-task/cloud-task-engine.ts b/products/desktop/packages/core/src/cloud-task/cloud-task-engine.ts
index accd17b161e2..0fa453e573da 100644
--- a/products/desktop/packages/core/src/cloud-task/cloud-task-engine.ts
+++ b/products/desktop/packages/core/src/cloud-task/cloud-task-engine.ts
@@ -25,7 +25,7 @@ import { type SseEvent, SseEventParser } from "./sse-parser";
// Reconnect backoff: flat base delay for the first SSE_RECONNECT_FLAT_ATTEMPTS attempts, then
// exponential up to the cap (0.5, 0.5, 0.5, 1, 2, 4, 8, 16, 30s), spanning ~60s before giving up.
-const MAX_SSE_RECONNECT_ATTEMPTS = 9;
+export const MAX_SSE_RECONNECT_ATTEMPTS = 9;
const MAX_CUMULATIVE_RECONNECT_ATTEMPTS = 30;
const SSE_RECONNECT_BASE_DELAY_MS = 500;
const SSE_RECONNECT_FLAT_ATTEMPTS = 3;
diff --git a/products/desktop/packages/core/src/cloud-task/cloud-task.test.ts b/products/desktop/packages/core/src/cloud-task/cloud-task.test.ts
index cc2ed6710c1f..cfc226b398d4 100644
--- a/products/desktop/packages/core/src/cloud-task/cloud-task.test.ts
+++ b/products/desktop/packages/core/src/cloud-task/cloud-task.test.ts
@@ -28,6 +28,7 @@ const fetchRouter = vi.hoisted(() =>
import {
type CloudTaskEngine,
createCloudTaskEngine,
+ MAX_SSE_RECONNECT_ATTEMPTS,
} from "./cloud-task-engine";
const mockAuthService = {
@@ -3212,7 +3213,10 @@ describe("CloudTaskEngine", () => {
retryable: true,
});
- expect(mockStreamFetch.mock.calls.length).toBeGreaterThan(2);
+ expect(mockStreamFetch.mock.calls.length).toBe(
+ 1 + MAX_SSE_RECONNECT_ATTEMPTS,
+ );
+ expect(mockStreamTokenFetch.mock.calls.length).toBe(1);
const streamCallsAtFailure = mockStreamFetch.mock.calls.length;
await vi.advanceTimersByTimeAsync(60_000);
expect(mockStreamFetch.mock.calls.length).toBe(streamCallsAtFailure);