Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions tests/ws-upstream.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, jest, test } from "bun:test";
import { afterEach, describe, expect, test } from "bun:test";
import { providerFetch } from "../src/server/responses/fetch-helpers";
import { handleResponses } from "../src/server/responses";
import { isEagerRelaySseResponse } from "../src/server/relay";
Expand Down Expand Up @@ -411,7 +411,11 @@ describe("codexWsUpstreamFetch", () => {
});

test("falls back to the HTTP fetch when the upgrade deadline elapses without open or close", async () => {
jest.useFakeTimers();
const realSetTimeout = globalThis.setTimeout;
globalThis.setTimeout = ((callback: () => void) => {
queueMicrotask(callback);
return 0 as unknown as ReturnType<typeof setTimeout>;
}) as unknown as typeof setTimeout;
try {
installFake(() => { /* handshake never settles */ });
const sentinel = new Response("sse-timeout-fallback", { status: 200 });
Expand All @@ -423,15 +427,14 @@ describe("codexWsUpstreamFetch", () => {

const responsePromise = codexWsUpstreamFetch(CODEX_URL, streamingInit(), fallback);
expect(FakeWebSocket.instances).toHaveLength(1);
jest.advanceTimersByTime(10_000);
const response = await responsePromise;

expect(response).toBe(sentinel);
expect(isCodexWsUpstreamResponse(response)).toBe(false);
expect(fallbackCalls).toBe(1);
expect(FakeWebSocket.instances[0].closed).toBe(true);
} finally {
jest.useRealTimers();
globalThis.setTimeout = realSetTimeout;
}
});

Expand Down
Loading