From bf1e4922b4e5015572fc4e63861a4bd35dd2e1d6 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 7 Jan 2026 23:39:10 -0800 Subject: [PATCH] Speed up some more tests (#25892) ### What does this PR do? ### How did you verify your code works? --- test/cli/install/bun-upgrade.test.ts | 317 +++++++++--------- test/harness.ts | 10 + .../AsyncLocalStorage-tracking.test.ts | 2 +- 3 files changed, 177 insertions(+), 152 deletions(-) diff --git a/test/cli/install/bun-upgrade.test.ts b/test/cli/install/bun-upgrade.test.ts index 189f8154a2..491c9a3c0b 100644 --- a/test/cli/install/bun-upgrade.test.ts +++ b/test/cli/install/bun-upgrade.test.ts @@ -1,178 +1,193 @@ -import { spawn, spawnSync } from "bun"; +import { spawn } from "bun"; import { upgrade_test_helpers } from "bun:internal-for-testing"; -import { beforeAll, beforeEach, expect, it, setDefaultTimeout } from "bun:test"; +import { beforeAll, describe, expect, it, setDefaultTimeout } from "bun:test"; import { bunExe, bunEnv as env, tls, tmpdirSync } from "harness"; -import { copyFileSync } from "node:fs"; +import { copyFile } from "node:fs/promises"; import { basename, join } from "path"; const { openTempDirWithoutSharingDelete, closeTempDirHandle } = upgrade_test_helpers; -let cwd: string; -let execPath: string; - beforeAll(() => { setDefaultTimeout(1000 * 60 * 5); }); -beforeEach(async () => { - cwd = tmpdirSync(); - execPath = join(cwd, basename(bunExe())); - copyFileSync(bunExe(), execPath); -}); +describe.concurrent(() => { + it("two invalid arguments, should display error message and suggest command", async () => { + const cwd = tmpdirSync(); + const execPath = join(cwd, basename(bunExe())); + await copyFile(bunExe(), execPath); + const { stderr } = spawn({ + cmd: [execPath, "upgrade", "bun-types", "--dev"], + cwd, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); -it("two invalid arguments, should display error message and suggest command", async () => { - const { stderr } = spawn({ - cmd: [execPath, "upgrade", "bun-types", "--dev"], - cwd, - stdout: null, - stdin: "pipe", - stderr: "pipe", - env, + const err = await stderr.text(); + expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names."); + expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types --dev` instead."); }); - const err = await stderr.text(); - expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names."); - expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types --dev` instead."); -}); + it("two invalid arguments flipped, should display error message and suggest command", async () => { + const cwd = tmpdirSync(); + const execPath = join(cwd, basename(bunExe())); + await copyFile(bunExe(), execPath); + const { stderr } = spawn({ + cmd: [execPath, "upgrade", "--dev", "bun-types"], + cwd, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); -it("two invalid arguments flipped, should display error message and suggest command", async () => { - const { stderr } = spawn({ - cmd: [execPath, "upgrade", "--dev", "bun-types"], - cwd, - stdout: null, - stdin: "pipe", - stderr: "pipe", - env, + const err = await stderr.text(); + expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names."); + expect(err.split(/\r?\n/)).toContain("note: Use `bun update --dev bun-types` instead."); }); - const err = await stderr.text(); - expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names."); - expect(err.split(/\r?\n/)).toContain("note: Use `bun update --dev bun-types` instead."); -}); + it("one invalid argument, should display error message and suggest command", async () => { + const cwd = tmpdirSync(); + const execPath = join(cwd, basename(bunExe())); + await copyFile(bunExe(), execPath); + const { stderr } = spawn({ + cmd: [execPath, "upgrade", "bun-types"], + cwd, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); -it("one invalid argument, should display error message and suggest command", async () => { - const { stderr } = spawn({ - cmd: [execPath, "upgrade", "bun-types"], - cwd, - stdout: null, - stdin: "pipe", - stderr: "pipe", - env, + const err = await stderr.text(); + expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names."); + expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types` instead."); }); - const err = await stderr.text(); - expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names."); - expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types` instead."); -}); + it("one valid argument, should succeed", async () => { + const cwd = tmpdirSync(); + const execPath = join(cwd, basename(bunExe())); + await copyFile(bunExe(), execPath); + const { stderr } = spawn({ + cmd: [execPath, "upgrade", "--help"], + cwd, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); -it("one valid argument, should succeed", async () => { - const { stderr } = spawn({ - cmd: [execPath, "upgrade", "--help"], - cwd, - stdout: null, - stdin: "pipe", - stderr: "pipe", - env, + const err = await stderr.text(); + // Should not contain error message + expect(err.split(/\r?\n/)).not.toContain( + "error: This command updates bun itself, and does not take package names.", + ); + expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --help` instead."); }); - const err = await stderr.text(); - // Should not contain error message - expect(err.split(/\r?\n/)).not.toContain("error: This command updates bun itself, and does not take package names."); - expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --help` instead."); -}); + it("two valid argument, should succeed", async () => { + const cwd = tmpdirSync(); + const execPath = join(cwd, basename(bunExe())); + await copyFile(bunExe(), execPath); + const { stderr } = spawn({ + cmd: [execPath, "upgrade", "--stable", "--profile"], + cwd, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); -it("two valid argument, should succeed", async () => { - const { stderr } = spawn({ - cmd: [execPath, "upgrade", "--stable", "--profile"], - cwd, - stdout: null, - stdin: "pipe", - stderr: "pipe", - env, + const err = await stderr.text(); + // Should not contain error message + expect(err.split(/\r?\n/)).not.toContain( + "error: This command updates Bun itself, and does not take package names.", + ); + expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --stable --profile` instead."); }); - const err = await stderr.text(); - // Should not contain error message - expect(err.split(/\r?\n/)).not.toContain("error: This command updates Bun itself, and does not take package names."); - expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --stable --profile` instead."); -}); + it("zero arguments, should succeed", async () => { + const tagName = bunExe().includes("-debug") ? "canary" : `bun-v${Bun.version}`; + using server = Bun.serve({ + tls: tls, + port: 0, + async fetch() { + return new Response( + JSON.stringify({ + "tag_name": tagName, + "assets": [ + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-windows-x64.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64.zip`, + }, + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-windows-x64-baseline.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64-baseline.zip`, + }, + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-linux-x64.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64.zip`, + }, + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-linux-x64-baseline.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64-baseline.zip`, + }, + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-darwin-x64.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64.zip`, + }, + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-darwin-x64-baseline.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64-baseline.zip`, + }, + { + "url": "foo", + "content_type": "application/zip", + "name": "bun-darwin-aarch64.zip", + "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-aarch64.zip`, + }, + ], + }), + ); + }, + }); -it("zero arguments, should succeed", async () => { - const tagName = bunExe().includes("-debug") ? "canary" : `bun-v${Bun.version}`; - using server = Bun.serve({ - tls: tls, - port: 0, - async fetch() { - return new Response( - JSON.stringify({ - "tag_name": tagName, - "assets": [ - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-windows-x64.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64.zip`, - }, - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-windows-x64-baseline.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-windows-x64-baseline.zip`, - }, - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-linux-x64.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64.zip`, - }, - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-linux-x64-baseline.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-linux-x64-baseline.zip`, - }, - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-darwin-x64.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64.zip`, - }, - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-darwin-x64-baseline.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-x64-baseline.zip`, - }, - { - "url": "foo", - "content_type": "application/zip", - "name": "bun-darwin-aarch64.zip", - "browser_download_url": `https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${tagName}/bun-darwin-aarch64.zip`, - }, - ], - }), - ); - }, + // On windows, open the temporary directory without FILE_SHARE_DELETE before spawning + // the upgrade process. This is to test for EBUSY errors + openTempDirWithoutSharingDelete(); + const cwd = tmpdirSync(); + const execPath = join(cwd, basename(bunExe())); + await copyFile(bunExe(), execPath); + + const { stderr } = Bun.spawn({ + cmd: [execPath, "upgrade"], + cwd, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env: { + ...env, + NODE_TLS_REJECT_UNAUTHORIZED: "0", + GITHUB_API_DOMAIN: `${server.hostname}:${server.port}`, + }, + }); + + closeTempDirHandle(); + + // Should not contain error message + expect(await stderr.text()).not.toContain("error:"); }); - - // On windows, open the temporary directory without FILE_SHARE_DELETE before spawning - // the upgrade process. This is to test for EBUSY errors - openTempDirWithoutSharingDelete(); - - const { stderr } = spawnSync({ - cmd: [execPath, "upgrade"], - cwd, - stdout: null, - stdin: "pipe", - stderr: "pipe", - env: { - ...env, - NODE_TLS_REJECT_UNAUTHORIZED: "0", - GITHUB_API_DOMAIN: `${server.hostname}:${server.port}`, - }, - }); - - closeTempDirHandle(); - - // Should not contain error message - expect(stderr.toString()).not.toContain("error:"); }); diff --git a/test/harness.ts b/test/harness.ts index 1cc1880b75..4bba068ad7 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -811,6 +811,16 @@ export async function toBeWorkspaceLink(actual: string, expectedLinkPath: string return { pass, message }; } +export function getFDCount(): number { + if (isMacOS || isLinux) { + return fs.readdirSync(isMacOS ? "/dev/fd" : "/proc/self/fd").length; + } + + const maxFD = openSync("/dev/null", "r"); + closeSync(maxFD); + return maxFD; +} + export function getMaxFD(): number { if (isMacOS || isLinux) { let max = -1; diff --git a/test/js/node/async_hooks/AsyncLocalStorage-tracking.test.ts b/test/js/node/async_hooks/AsyncLocalStorage-tracking.test.ts index 7e77f3141e..59cbb711dc 100644 --- a/test/js/node/async_hooks/AsyncLocalStorage-tracking.test.ts +++ b/test/js/node/async_hooks/AsyncLocalStorage-tracking.test.ts @@ -3,7 +3,7 @@ import { describe, test } from "bun:test"; import { bunEnv, bunExe, isASAN, isBroken, isLinux, nodeExe } from "harness"; import { basename, join } from "path"; -describe("AsyncLocalStorage passes context to callbacks", () => { +describe.concurrent("AsyncLocalStorage passes context to callbacks", () => { let files = [...new Glob(join(import.meta.dir, "async-context", "async-context-*.js")).scanSync()]; let todos = ["async-context-worker_threads-message.js"];