Repository navigation
Expand file tree
/
Copy pathmini-timeout.test.ts
More file actions
47 lines (46 loc) · 1.68 KB
/
Copy pathmini-timeout.test.ts
File metadata and controls
47 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { expect, test } from "bun:test"
import path from "node:path"
import { isolatedEnv } from "./fixture/environment"
import { tmpdir } from "./fixture/tmpdir"
test("mini waits beyond the fetch idle timeout before and after reconnecting", async () => {
await using directory = await tmpdir()
const requests: string[] = []
const server = Bun.serve({
hostname: "127.0.0.1",
port: 0,
idleTimeout: 0,
async fetch(request) {
requests.push(new URL(request.url).pathname)
// Bun's socket timer sweeps every four seconds, so allow more than two sweeps.
await Bun.sleep(12_000)
return new Response(null, { status: 204 })
},
})
const child = Bun.spawn(
[process.execPath, path.join(import.meta.dir, "fixture/mini-wait.ts"), server.url.toString()],
{
cwd: path.join(import.meta.dir, ".."),
env: isolatedEnv(directory.path, { BUN_CONFIG_HTTP_IDLE_TIMEOUT: "1" }),
signal: AbortSignal.timeout(25_000),
stdout: "pipe",
stderr: "pipe",
},
)
try {
const [stdout, stderr, code] = await Promise.all([
new Response(child.stdout).text(),
new Response(child.stderr).text(),
child.exited,
])
expect(stderr).not.toContain("Transport: The operation timed out")
expect(stderr).not.toContain("TimeoutError")
expect({ stdout, code }).toEqual({ stdout: "", code: 0 })
expect(requests.filter((path) => path !== "/api/experimental/session/ses_cancelled/wait").toSorted()).toEqual(
["ses_initial", "ses_reconnected", "ses_control"].map((id) => `/api/experimental/session/${id}/wait`).sort(),
)
} finally {
child.kill()
await child.exited
await server.stop(true)
}
}, 30_000)