Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 12 additions & 7 deletions test/js/bun/shell/leak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const TESTS: [name: string, builder: () => TestBuilder, runs?: number][] = [
],
];

describe("fd leak", () => {
describe.concurrent("fd leak", () => {
function fdLeakTest(name: string, builder: () => TestBuilder, runs: number = 1000, threshold: number = 5) {
test(`fdleak_${name}`, async () => {
Bun.gc(true);
Expand Down Expand Up @@ -123,12 +123,14 @@ describe("fd leak", () => {

// console.log("THE CODE", readFileSync(tempfile, "utf-8"));

const { stdout, stderr, exitCode } = Bun.spawnSync([process.argv0, "--smol", "test", tempfile], {
const { exited, stderr: stream } = Bun.spawn([process.argv0, "--smol", "test", tempfile], {
env: bunEnv,
stderr: "pipe",
});
const [exitCode, stderr] = await Promise.all([exited, stream.text()]);
// console.log("STDOUT:", stdout.toString(), "\n\nSTDERR:", stderr.toString());
if (exitCode != 0) {
console.log("\n\nSTDERR:", stderr.toString());
console.log("\n\nSTDERR:", stderr);
}
expect(exitCode).toBe(0);
}, 100_000);
Expand Down Expand Up @@ -215,12 +217,15 @@ describe("fd leak", () => {

// console.log("THE CODE", readFileSync(tempfile, "utf-8"));

const { stdout, stderr, exitCode } = Bun.spawnSync([process.argv0, "--smol", "test", tempfile], {
const { stderr: stream, exited } = Bun.spawn([process.argv0, "--smol", "test", tempfile], {
env: bunEnv,
stdout: "ignore",
stderr: "pipe",
});
const [exitCode, stderr] = await Promise.all([exited, stream.text()]);
// console.log("STDOUT:", stdout.toString(), "\n\nSTDERR:", stderr.toString());
if (exitCode != 0) {
console.log("\n\nSTDERR:", stderr.toString());
console.log("\n\nSTDERR:", stderr);
}
expect(exitCode).toBe(0);
},
Expand Down Expand Up @@ -373,7 +378,7 @@ describe("fd leak", () => {
true,
);

describe("#11816", async () => {
describe.serial("#11816", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Unnecessary async keyword on describe callback.

The async on this describe callback is unnecessary since there's no await in the callback body. Line 414 correctly omits it.

Suggested fix
-  describe.serial("#11816", async () => {
+  describe.serial("#11816", () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe.serial("#11816", async () => {
describe.serial("#11816", () => {
🤖 Prompt for AI Agents
In @test/js/bun/shell/leak.test.ts at line 381, Remove the unnecessary async
from the describe.serial callback for "#11816" (i.e., change
describe.serial("#11816", async () => { ... }) to describe.serial("#11816", ()
=> { ... })), since the callback contains no await and the async keyword is
redundant.

function doit(builtin: boolean) {
test(builtin ? "builtin" : "external", async () => {
const files = tempDirWithFiles("hi", {
Expand Down Expand Up @@ -406,7 +411,7 @@ describe("fd leak", () => {
doit(true);
});

describe("not leaking ParsedShellScript when ShellInterpreter never runs", async () => {
describe.serial("not leaking ParsedShellScript when ShellInterpreter never runs", () => {
function doit(builtin: boolean) {
test(builtin ? "builtin" : "external", async () => {
const files = tempDirWithFiles("hi", {
Expand Down
16 changes: 0 additions & 16 deletions test/js/bun/shell/test_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ import { join } from "node:path";
export function createTestBuilder(path: string) {
var { describe, test, afterAll, beforeAll, expect, beforeEach, afterEach } = Bun.jest(path);

var insideTestScope = false;
beforeEach(() => {
insideTestScope = true;
});
afterEach(() => {
insideTestScope = false;
});

class TestBuilder {
_testName: string | undefined = undefined;

Expand Down Expand Up @@ -247,14 +239,6 @@ export function createTestBuilder(path: string) {
}

async run(): Promise<undefined> {
if (!insideTestScope) {
const err = new Error("TestBuilder.run() must be called inside a test scope");
test("TestBuilder.run() must be called inside a test scope", () => {
throw err;
});
return Promise.resolve(undefined);
}

try {
let finalPromise = Bun.$(this._scriptStr, ...this._expresssions);
if (this.tempdir) finalPromise = finalPromise.cwd(this.tempdir);
Expand Down