From 61d0690697ee2856bf74f98687f427f1d32380bf Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Sat, 28 Dec 2024 02:25:22 -0800 Subject: [PATCH] leak test in their own file --- test/js/bun/s3/s3.leak.test.ts | 109 +++++++++++++++++++++++++++++++++ test/js/bun/s3/s3.test.ts | 96 ----------------------------- 2 files changed, 109 insertions(+), 96 deletions(-) create mode 100644 test/js/bun/s3/s3.leak.test.ts diff --git a/test/js/bun/s3/s3.leak.test.ts b/test/js/bun/s3/s3.leak.test.ts new file mode 100644 index 00000000000000..2008cae89a09a4 --- /dev/null +++ b/test/js/bun/s3/s3.leak.test.ts @@ -0,0 +1,109 @@ +import { describe, expect, it } from "bun:test"; +import { bunExe, bunEnv, getSecret, tempDirWithFiles } from "harness"; +import type { S3FileOptions } from "bun"; +import path from "path"; +const s3Options: S3FileOptions = { + accessKeyId: getSecret("S3_R2_ACCESS_KEY"), + secretAccessKey: getSecret("S3_R2_SECRET_KEY"), + endpoint: getSecret("S3_R2_ENDPOINT"), +}; + +const S3Bucket = getSecret("S3_R2_BUCKET"); + +describe.skipIf(!s3Options.accessKeyId)("s3", () => { + describe("leak tests", () => { + it( + "fsFile.stream() should not leak", + async () => { + const dir = tempDirWithFiles("s3-stream-leak-fixture", { + "s3-stream-leak-fixture.js": await Bun.file(path.join(import.meta.dir, "s3-stream-leak-fixture.js")).text(), + "out.bin": "here", + }); + + const dest = path.join(dir, "out.bin"); + + const { exitCode, stderr } = Bun.spawnSync( + [bunExe(), "--smol", path.join(dir, "s3-stream-leak-fixture.js"), dest], + { + env: { + ...bunEnv, + BUN_JSC_gcMaxHeapSize: "503316", + AWS_ACCESS_KEY_ID: s3Options.accessKeyId, + AWS_SECRET_ACCESS_KEY: s3Options.secretAccessKey, + AWS_ENDPOINT: s3Options.endpoint, + AWS_BUCKET: S3Bucket, + }, + stderr: "pipe", + stdout: "inherit", + stdin: "ignore", + }, + ); + expect(exitCode).toBe(0); + expect(stderr.toString()).toBe(""); + }, + 30 * 1000, + ); + it( + "fsFile.writer().write() should not leak", + async () => { + const dir = tempDirWithFiles("s3-writer-leak-fixture", { + "s3-writer-leak-fixture.js": await Bun.file(path.join(import.meta.dir, "s3-writer-leak-fixture.js")).text(), + "out.bin": "here", + }); + + const dest = path.join(dir, "out.bin"); + + const { exitCode, stderr } = Bun.spawnSync( + [bunExe(), "--smol", path.join(dir, "s3-writer-leak-fixture.js"), dest], + { + env: { + ...bunEnv, + BUN_JSC_gcMaxHeapSize: "503316", + AWS_ACCESS_KEY_ID: s3Options.accessKeyId, + AWS_SECRET_ACCESS_KEY: s3Options.secretAccessKey, + AWS_ENDPOINT: s3Options.endpoint, + AWS_BUCKET: S3Bucket, + }, + stderr: "pipe", + stdout: "inherit", + stdin: "ignore", + }, + ); + expect(exitCode).toBe(0); + expect(stderr.toString()).toBe(""); + }, + 30 * 1000, + ); + it( + "Bun.write should not leak", + async () => { + const dir = tempDirWithFiles("bun-write-leak-fixture", { + "bun-write-leak-fixture.js": await Bun.file(path.join(import.meta.dir, "bun-write-leak-fixture.js")).text(), + "out.bin": "here", + }); + + const dest = path.join(dir, "out.bin"); + + const { exitCode, stderr } = Bun.spawnSync( + [bunExe(), "--smol", path.join(dir, "bun-write-leak-fixture.js"), dest], + { + env: { + ...bunEnv, + BUN_JSC_gcMaxHeapSize: "503316", + AWS_ACCESS_KEY_ID: s3Options.accessKeyId, + AWS_SECRET_ACCESS_KEY: s3Options.secretAccessKey, + AWS_ENDPOINT: s3Options.endpoint, + AWS_BUCKET: S3Bucket, + }, + stderr: "pipe", + stdout: "inherit", + stdin: "ignore", + }, + ); + expect(exitCode).toBe(0); + expect(stderr.toString()).toBe(""); + }, + 30 * 1000, + ); + }); +}); diff --git a/test/js/bun/s3/s3.test.ts b/test/js/bun/s3/s3.test.ts index ca87dd9fca9e40..91452cf72e707e 100644 --- a/test/js/bun/s3/s3.test.ts +++ b/test/js/bun/s3/s3.test.ts @@ -615,100 +615,4 @@ describe.skipIf(!s3Options.accessKeyId)("s3", () => { await s3file.unlink(); }); }); - - describe("leak tests", () => { - it( - "fsFile.stream() should not leak", - async () => { - const dir = tempDirWithFiles("s3-stream-leak-fixture", { - "s3-stream-leak-fixture.js": await Bun.file(path.join(import.meta.dir, "s3-stream-leak-fixture.js")).text(), - "out.bin": "here", - }); - - const dest = path.join(dir, "out.bin"); - - const { exitCode, stderr } = Bun.spawnSync( - [bunExe(), "--smol", path.join(dir, "s3-stream-leak-fixture.js"), dest], - { - env: { - ...bunEnv, - BUN_JSC_gcMaxHeapSize: "503316", - AWS_ACCESS_KEY_ID: s3Options.accessKeyId, - AWS_SECRET_ACCESS_KEY: s3Options.secretAccessKey, - AWS_ENDPOINT: s3Options.endpoint, - AWS_BUCKET: S3Bucket, - }, - stderr: "pipe", - stdout: "inherit", - stdin: "ignore", - }, - ); - expect(exitCode).toBe(0); - expect(stderr.toString()).toBe(""); - }, - 30 * 1000, - ); - it( - "fsFile.writer().write() should not leak", - async () => { - const dir = tempDirWithFiles("s3-writer-leak-fixture", { - "s3-writer-leak-fixture.js": await Bun.file(path.join(import.meta.dir, "s3-writer-leak-fixture.js")).text(), - "out.bin": "here", - }); - - const dest = path.join(dir, "out.bin"); - - const { exitCode, stderr } = Bun.spawnSync( - [bunExe(), "--smol", path.join(dir, "s3-writer-leak-fixture.js"), dest], - { - env: { - ...bunEnv, - BUN_JSC_gcMaxHeapSize: "503316", - AWS_ACCESS_KEY_ID: s3Options.accessKeyId, - AWS_SECRET_ACCESS_KEY: s3Options.secretAccessKey, - AWS_ENDPOINT: s3Options.endpoint, - AWS_BUCKET: S3Bucket, - }, - stderr: "pipe", - stdout: "inherit", - stdin: "ignore", - }, - ); - expect(exitCode).toBe(0); - expect(stderr.toString()).toBe(""); - }, - 30 * 1000, - ); - it( - "Bun.write should not leak", - async () => { - const dir = tempDirWithFiles("bun-write-leak-fixture", { - "bun-write-leak-fixture.js": await Bun.file(path.join(import.meta.dir, "bun-write-leak-fixture.js")).text(), - "out.bin": "here", - }); - - const dest = path.join(dir, "out.bin"); - - const { exitCode, stderr } = Bun.spawnSync( - [bunExe(), "--smol", path.join(dir, "bun-write-leak-fixture.js"), dest], - { - env: { - ...bunEnv, - BUN_JSC_gcMaxHeapSize: "503316", - AWS_ACCESS_KEY_ID: s3Options.accessKeyId, - AWS_SECRET_ACCESS_KEY: s3Options.secretAccessKey, - AWS_ENDPOINT: s3Options.endpoint, - AWS_BUCKET: S3Bucket, - }, - stderr: "pipe", - stdout: "inherit", - stdin: "ignore", - }, - ); - expect(exitCode).toBe(0); - expect(stderr.toString()).toBe(""); - }, - 30 * 1000, - ); - }); });