Compare commits

...

1 Commits

Author SHA1 Message Date
pfg
35bc011c28 skip flaky tests 2024-12-10 14:23:49 -08:00
8 changed files with 70 additions and 56 deletions

View File

@@ -313,6 +313,7 @@ it(
const contents = readFileSync(root, "utf-8");
rmSync(root);
writeFileSync(root, contents);
Bun.sleepSync(100);
}
var str = "";
@@ -370,13 +371,10 @@ it(
async function onReload() {
const contents = readFileSync(root, "utf-8");
rmSync(root + ".tmpfile", { force: true });
await 1;
writeFileSync(root + ".tmpfile", contents);
await 1;
rmSync(root);
await 1;
renameSync(root + ".tmpfile", root);
await 1;
await Bun.sleep(100);
}
var str = "";
@@ -440,6 +438,7 @@ throw new Error('0');`,
${comment_spam}
${" ".repeat(reloadCounter * 2)}throw new Error(${reloadCounter});`,
);
Bun.sleepSync(100);
}
let str = "";
outer: for await (const chunk of runner.stderr) {
@@ -520,6 +519,7 @@ throw new Error('0');`,
// etc etc
${" ".repeat(reloadCounter * 2)}throw new Error(${reloadCounter});`,
);
Bun.sleepSync(100);
}
let str = "";
outer: for await (const chunk of runner.stderr) {

View File

@@ -279,16 +279,20 @@ describe("files transpiled and loaded don't leak the AST", () => {
// These tests are extra slow in debug builds
describe("files transpiled and loaded don't leak file paths", () => {
test("via require()", () => {
const { stdout, exitCode } = Bun.spawnSync({
cmd: [bunExe(), "--smol", "run", join(import.meta.dir, "cjs-fixture-leak-small.js")],
env: bunEnv,
stderr: "inherit",
});
test.todoIf(isWindows)(
"via require()",
() => {
const { stdout, exitCode } = Bun.spawnSync({
cmd: [bunExe(), "--smol", "run", join(import.meta.dir, "cjs-fixture-leak-small.js")],
env: bunEnv,
stderr: "inherit",
});
expect(stdout.toString().trim()).toEndWith("--pass--");
expect(exitCode).toBe(0);
}, 30000);
expect(stdout.toString().trim()).toEndWith("--pass--");
expect(exitCode).toBe(0);
},
30000,
);
test(
"via import()",

View File

@@ -3,7 +3,7 @@ import { expect, test } from "bun:test";
import { copyFileSync, cpSync, promises as fs, readFileSync, rmSync } from "fs";
import { cp } from "fs/promises";
import { join } from "path";
import { bunEnv, bunExe, isDebug, tmpdirSync, toMatchNodeModulesAt } from "../../../harness";
import { bunEnv, bunExe, isDebug, isLinux, isWindows, tmpdirSync, toMatchNodeModulesAt } from "../../../harness";
const { parseLockfile } = install_test_helpers;
expect.extend({ toMatchNodeModulesAt });
@@ -93,7 +93,7 @@ function normalizeOutput(stdout: string) {
);
}
test(
test.skipIf(isWindows || (isLinux && process.arch === "x64"))(
"next build works",
async () => {
rmSync(join(root, ".next"), { recursive: true, force: true });

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { fileDescriptorLeakChecker, isWindows, tmpdirSync } from "harness";
import { fileDescriptorLeakChecker, isWindows, libcFamily, tmpdirSync } from "harness";
import { mkfifo } from "mkfifo";
import { join } from "node:path";
@@ -170,7 +170,8 @@ import fs from "node:fs";
import path from "node:path";
import util from "node:util";
it("end doesn't close when backed by a file descriptor", async () => {
// leaks fd on musl
it.todoIf(libcFamily == "musl")("end doesn't close when backed by a file descriptor", async () => {
using _ = fileDescriptorLeakChecker();
const x = tmpdirSync();
const fd = await util.promisify(fs.open)(path.join(x, "test.txt"), "w");

View File

@@ -8,7 +8,7 @@ test("sleep should saturate timeout values", async () => {
"999999999999999.999999999999999",
"999999999999999",
];
const fixturesThatSHouldCompleteInstantly = [
const fixturesThatShouldCompleteInstantly = [
"0",
"0.0",
"-0",
@@ -31,7 +31,7 @@ test("sleep should saturate timeout values", async () => {
});
const start = performance.now();
const toWait = fixturesThatSHouldCompleteInstantly.map(async timeout => {
const toWait = fixturesThatShouldCompleteInstantly.map(async timeout => {
const proc = Bun.spawn({
cmd: [bunExe(), "sleep-4ever.js", timeout],
stderr: "inherit",
@@ -41,7 +41,7 @@ test("sleep should saturate timeout values", async () => {
cwd: import.meta.dir,
});
expect(await proc.exited).toBe(0);
expect(performance.now() - start).toBeLessThan(1000);
expect(performance.now() - start).toBeLessThan(2000);
});
await Promise.all(toWait);

View File

@@ -93,60 +93,69 @@ export function createDenoTest(path: string, defaultTimeout = 5000) {
// Deno's assertions implemented using expect().
// https://github.com/denoland/deno/blob/main/cli/tests/unit/test_util.ts
const assert = (condition: unknown, message?: string) => {
const handleError = (message: string | undefined, cb: () => void) => {
try {
cb();
} catch (error) {
console.error(message);
throw error;
}
};
const assert = (condition: unknown, message?: string) => handleError(message, () => {
expect(condition).toBeTruthy();
};
});
const assertFalse = (condition: unknown, message?: string) => {
const assertFalse = (condition: unknown, message?: string) => handleError(message, () => {
expect(condition).toBeFalsy();
};
});
const assertEquals = (actual: unknown, expected: unknown, message?: string) => {
const assertEquals = (actual: unknown, expected: unknown, message?: string) => handleError(message, () => {
expect(actual).toEqual(expected);
};
});
const assertExists = (value: unknown, message?: string) => {
const assertExists = (value: unknown, message?: string) => handleError(message, () => {
expect(value).toBeDefined();
};
});
const assertNotEquals = (actual: unknown, expected: unknown, message?: string) => {
const assertNotEquals = (actual: unknown, expected: unknown, message?: string) => handleError(message, () => {
expect(actual).not.toEqual(expected);
};
});
const assertStrictEquals = (actual: unknown, expected: unknown, message?: string) => {
const assertStrictEquals = (actual: unknown, expected: unknown, message?: string) => handleError(message, () => {
expect(actual).toStrictEqual(expected);
};
});
const assertNotStrictEquals = (actual: unknown, expected: unknown, message?: string) => {
const assertNotStrictEquals = (actual: unknown, expected: unknown, message?: string) => handleError(message, () => {
expect(actual).not.toStrictEqual(expected);
};
});
const assertAlmostEquals = (actual: unknown, expected: number, epsilon: number = 1e-7, message?: string) => {
const assertAlmostEquals = (actual: unknown, expected: number, epsilon: number = 1e-7, message?: string) => handleError(message, () => {
if (typeof actual === "number") {
// TODO: toBeCloseTo()
expect(Math.abs(actual - expected)).toBeLessThanOrEqual(epsilon);
} else {
expect(typeof actual).toBe("number");
}
};
});
const assertInstanceOf = (actual: unknown, expected: unknown, message?: string) => {
const assertInstanceOf = (actual: unknown, expected: unknown, message?: string) => handleError(message, () => {
expect(actual).toBeInstanceOf(expected);
};
});
const assertNotInstanceOf = (actual: unknown, expected: unknown, message?: string) => {
const assertNotInstanceOf = (actual: unknown, expected: unknown, message?: string) => handleError(message, () => {
expect(actual).not.toBeInstanceOf(expected);
};
});
const assertStringIncludes = (actual: unknown, expected: string, message?: string) => {
const assertStringIncludes = (actual: unknown, expected: string, message?: string) => handleError(message, () => {
if (typeof actual === "string") {
expect(actual).toContain(expected);
} else {
expect(typeof actual).toBe("string");
}
};
});
const assertArrayIncludes = (actual: unknown, expected: unknown[], message?: string) => {
const assertArrayIncludes = (actual: unknown, expected: unknown[], message?: string) => handleError(message, () => {
if (Array.isArray(actual)) {
for (const value of expected) {
expect(actual).toContain(value);
@@ -154,25 +163,25 @@ export function createDenoTest(path: string, defaultTimeout = 5000) {
} else {
expect(Array.isArray(actual)).toBe(true);
}
};
});
const assertMatch = (actual: unknown, expected: RegExp, message?: string) => {
const assertMatch = (actual: unknown, expected: RegExp, message?: string) => handleError(message, () => {
if (typeof actual === "string") {
expect(expected.test(actual)).toBe(true);
} else {
expect(typeof actual).toBe("string");
}
};
});
const assertNotMatch = (actual: unknown, expected: RegExp, message?: string) => {
const assertNotMatch = (actual: unknown, expected: RegExp, message?: string) => handleError(message, () => {
if (typeof actual === "string") {
expect(expected.test(actual)).toBe(false);
} else {
expect(typeof actual).toBe("string");
}
};
});
const assertObjectMatch = (actual: unknown, expected: Record<PropertyKey, unknown>, message?: string) => {
const assertObjectMatch = (actual: unknown, expected: Record<PropertyKey, unknown>, message?: string) => handleError(message, () => {
if (typeof actual === "object") {
// TODO: toMatchObject()
if (actual !== null) {
@@ -190,9 +199,9 @@ export function createDenoTest(path: string, defaultTimeout = 5000) {
} else {
expect(typeof actual).toBe("object");
}
};
});
const assertThrows = (fn: () => void, message?: string) => {
const assertThrows = (fn: () => void, message?: string) => handleError(message, () => {
try {
fn();
} catch (error) {
@@ -200,9 +209,9 @@ export function createDenoTest(path: string, defaultTimeout = 5000) {
return;
}
throw new Error("Expected an error to be thrown");
};
});
const assertRejects = async (fn: () => Promise<unknown>, message?: string) => {
const assertRejects = async (fn: () => Promise<unknown>, message?: string) => handleError(message, async () => {
try {
await fn();
} catch (error) {
@@ -210,7 +219,7 @@ export function createDenoTest(path: string, defaultTimeout = 5000) {
return;
}
throw new Error("Expected an error to be thrown");
};
});
const equal = (a: unknown, b: unknown) => {
return deepEquals(a, b);

View File

@@ -90,7 +90,7 @@ test(function performanceMeasure() {
assertEquals(measure2.startTime, 0);
assertEquals(mark1.startTime, measure1.startTime);
assertEquals(mark1.startTime, measure2.duration);
assert(measure1.duration >= 100, `duration below 100ms: ${measure1.duration}`);
assert(measure1.duration >= 85, `duration below 85ms: ${measure1.duration}`);
assert(
measure1.duration < (later - now) * 1.5,
`duration exceeds 150% of wallclock time: ${measure1.duration}ms vs ${later - now}ms`,

View File

@@ -2225,7 +2225,7 @@ describe("fs.ReadStream", () => {
});
describe("createWriteStream", () => {
it("simple write stream finishes", async () => {
it.todoIf(isWindows)("simple write stream finishes", async () => {
const path = `${tmpdir()}/fs.test.ts/${Date.now()}.createWriteStream.txt`;
const stream = createWriteStream(path);
stream.write("Test file written successfully");