Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions src/tests/client-fetch-delegate-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ try {
pull(controller) { emptyPulls++; controller.enqueue(new Uint8Array()); },
cancel() { emptyCancelled = true; },
}, { highWaterMark: 0 });
const emptyStart = Date.now();
const emptyStart = performance.now();
await assert.rejects(uploadRequest(base + '/empty-upload', { method: 'POST', body: emptyBody }), RequestTimeoutError);
assert.ok(emptyPulls > 64);
assert.equal(emptyCancelled, true);
assert.ok(Date.now() - emptyStart >= budget);
assert.ok(Date.now() - emptyStart < budget * 5);
const emptyElapsed = performance.now() - emptyStart;
// Native timers can wake slightly early; allow 5ms of scheduler rounding,
// while still rejecting premature aborts and empty chunks resetting the timer.
assert.ok(emptyElapsed >= budget - 5, `empty upload timed out too early: ${emptyElapsed}ms`);
assert.ok(emptyElapsed < budget * 5, `empty upload did not time out promptly: ${emptyElapsed}ms`);
assert.deepEqual(await uploadRequest(base + '/slow-response', { method: 'POST', body: 'once' }), { ok: true });
await assert.rejects(uploadRequest(base + '/stalled-response', { method: 'POST', body: 'once' }), RequestTimeoutError);

Expand Down
9 changes: 7 additions & 2 deletions src/tests/workers-build-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spawn, type ChildProcess } from "node:child_process";
import { existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { build } from "esbuild";

const pause = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
Expand All @@ -19,7 +20,11 @@ function running(pid: number) {
// rather than a mocked ChildProcess or Bun's differing signal implementation.
async function fixture(mode: "normal" | "stubborn" | "pipes", timeoutMs: number) {
const root = mkdtempSync(join(tmpdir(), "xapi-build-process-"));
symlinkSync(new URL("../../node_modules", import.meta.url).pathname, join(root, "node_modules"), process.platform === "win32" ? "junction" : "dir");
symlinkSync(fileURLToPath(new URL("../../node_modules", import.meta.url)), join(root, "node_modules"), process.platform === "win32" ? "junction" : "dir");
// Always cover URL escaping, even when the checkout path has no spaces.
const source = join(root, "source files #%");
symlinkSync(fileURLToPath(new URL("../", import.meta.url)), source, process.platform === "win32" ? "junction" : "dir");
const buildModule = pathToFileURL(join(source, "workers-project-build.ts"));
writeFileSync(join(root, "package.json"), JSON.stringify({ type: "module", scripts: { build: "node parent.cjs" } }));
writeFileSync(join(root, "parent.cjs"), `
const {spawn} = require('node:child_process');
Expand All @@ -38,7 +43,7 @@ async function fixture(mode: "normal" | "stubborn" | "pipes", timeoutMs: number)
${mode === "normal" ? "writeFileSync('worker.mjs', 'export default {}');" : "setTimeout(() => {writeFileSync('late-output', 'must not happen'); console.log('late-stdout'); console.error('late-stderr');}, 4000); setInterval(() => {}, 1000);"}
`);
writeFileSync(join(root, "runner.ts"), `
import {runWorkerProjectBuild} from ${JSON.stringify(new URL("../workers-project-build.ts", import.meta.url).pathname)};
import {runWorkerProjectBuild} from ${JSON.stringify(fileURLToPath(buildModule))};
try { await runWorkerProjectBuild('npm run build', ${JSON.stringify(root)}, ${timeoutMs}); console.log('build-complete'); }
catch(error) { console.error(error.message); process.exitCode = 1; }
`);
Expand Down
Loading