diff options
author | 2022-04-02 00:29:26 -0700 | |
---|---|---|
committer | 2022-04-02 00:29:26 -0700 | |
commit | 66c5a941b306bb2963c637f7207f15a7526781c3 (patch) | |
tree | a84e071e9a7a9d836c33b2324f7e66836b717765 /integration/bunjs-only-snippets | |
parent | 4592b1ccb57b00bbbffb1448609a70af0d362777 (diff) | |
download | bun-66c5a941b306bb2963c637f7207f15a7526781c3.tar.gz bun-66c5a941b306bb2963c637f7207f15a7526781c3.tar.zst bun-66c5a941b306bb2963c637f7207f15a7526781c3.zip |
More aggressive GC
Diffstat (limited to 'integration/bunjs-only-snippets')
-rw-r--r-- | integration/bunjs-only-snippets/html-rewriter.test.js | 4 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/mmap.test.js | 94 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/response.file.test.js | 14 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/url.test.ts | 14 |
4 files changed, 62 insertions, 64 deletions
diff --git a/integration/bunjs-only-snippets/html-rewriter.test.js b/integration/bunjs-only-snippets/html-rewriter.test.js index 68e2849d9..29b765c2f 100644 --- a/integration/bunjs-only-snippets/html-rewriter.test.js +++ b/integration/bunjs-only-snippets/html-rewriter.test.js @@ -1,4 +1,5 @@ import { describe, it, expect } from "bun:test"; +import { gcTick } from "./gc"; var setTimeoutAsync = (fn, delay) => { return new Promise((resolve, reject) => { @@ -14,6 +15,7 @@ var setTimeoutAsync = (fn, delay) => { describe("HTMLRewriter", () => { it("HTMLRewriter: async replacement", async () => { + await gcTick(); const res = new HTMLRewriter() .on("div", { async element(element) { @@ -23,7 +25,9 @@ describe("HTMLRewriter", () => { }, }) .transform(new Response("<div>example.com</div>")); + await gcTick(); expect(await res.text()).toBe("<div><span>replace</span></div>"); + await gcTick(); }); it("supports element handlers", async () => { diff --git a/integration/bunjs-only-snippets/mmap.test.js b/integration/bunjs-only-snippets/mmap.test.js index 3dd3aadb9..2b15a4000 100644 --- a/integration/bunjs-only-snippets/mmap.test.js +++ b/integration/bunjs-only-snippets/mmap.test.js @@ -1,49 +1,69 @@ import { describe, it, expect } from "bun:test"; +import { gcTick } from "./gc"; -const path = `/tmp/bun-mmap-test_${Math.random()}.txt`; +describe("Bun.mmap", async () => { + await gcTick(); + const path = `/tmp/bun-mmap-test_${Math.random()}.txt`; + await gcTick(); + await Bun.write(path, "hello"); + await gcTick(); -await Bun.write(path, "hello"); + it("mmap finalizer", async () => { + let map = Bun.mmap(path); + await gcTick(); + const map2 = Bun.mmap(path); -it("mmap finalizer", async () => { - let map = Bun.mmap(path); - const map2 = Bun.mmap(path); + map = null; + await gcTick(); + }); - map = null; - Bun.gc(true); - await new Promise((resolve) => setTimeout(resolve, 1)); -}); - -it("mmap passed to other syscalls", async () => { - const map = Bun.mmap(path); - await Bun.write(path + "1", map); - const text = await (await Bun.file(path + "1")).text(); - - expect(text).toBe(new TextDecoder().decode(map)); -}); + it("mmap passed to other syscalls", async () => { + const map = Bun.mmap(path); + await gcTick(); + await Bun.write(path + "1", map); + await gcTick(); + const text = await (await Bun.file(path + "1")).text(); + await gcTick(); -it("mmap sync", async () => { - const map = Bun.mmap(path); - const map2 = Bun.mmap(path); + expect(text).toBe(new TextDecoder().decode(map)); + }); - const old = map[0]; + it("mmap sync", async () => { + const map = Bun.mmap(path); + await gcTick(); + const map2 = Bun.mmap(path); + await gcTick(); - map[0] = 0; - expect(map2[0]).toBe(0); - - map2[0] = old; - expect(map[0]).toBe(old); - - await Bun.write(path, "olleh"); - expect(new TextDecoder().decode(map)).toBe("olleh"); -}); + const old = map[0]; + await gcTick(); + map[0] = 0; + await gcTick(); + expect(map2[0]).toBe(0); -it("mmap private", () => { - const map = Bun.mmap(path, { shared: true }); - const map2 = Bun.mmap(path, { shared: false }); + map2[0] = old; + await gcTick(); + expect(map[0]).toBe(old); + await gcTick(); + await Bun.write(path, "olleh"); + await gcTick(); + expect(new TextDecoder().decode(map)).toBe("olleh"); + await gcTick(); + }); - const old = map[0]; + it("mmap private", async () => { + await gcTick(); + const map = Bun.mmap(path, { shared: true }); + await gcTick(); + const map2 = Bun.mmap(path, { shared: false }); + await gcTick(); + const old = map[0]; - map2[0] = 0; - expect(map2[0]).toBe(0); - expect(map[0]).toBe(old); + await gcTick(); + map2[0] = 0; + await gcTick(); + expect(map2[0]).toBe(0); + await gcTick(); + expect(map[0]).toBe(old); + await gcTick(); + }); }); diff --git a/integration/bunjs-only-snippets/response.file.test.js b/integration/bunjs-only-snippets/response.file.test.js index 8444cef33..97e5902c5 100644 --- a/integration/bunjs-only-snippets/response.file.test.js +++ b/integration/bunjs-only-snippets/response.file.test.js @@ -1,19 +1,7 @@ import fs from "fs"; import { it, expect } from "bun:test"; import path from "path"; - -function gc() { - Bun.gc(true); -} - -// we must ensure that finalizers are run -// so that the reference-counting logic is exercised -function gcTick() { - gc(); - return new Promise((resolve) => { - setTimeout(resolve, 0); - }); -} +import { gcTick } from "./gc"; it("Bun.file not found returns ENOENT", async () => { try { diff --git a/integration/bunjs-only-snippets/url.test.ts b/integration/bunjs-only-snippets/url.test.ts index 9bead1f4e..2814d729b 100644 --- a/integration/bunjs-only-snippets/url.test.ts +++ b/integration/bunjs-only-snippets/url.test.ts @@ -84,19 +84,5 @@ describe("url", () => { expect(result.search).toBe(values.search); expect(result.username).toBe(values.username); } - - expect(new URL("example.com").pathname).toBe("/"); - expect(new URL("https://example.com").protocol).toBe("https:"); - expect(new URL("http://example.com").protocol).toBe("http:"); - expect(new URL("example.com/foo").pathname).toBe("/foo"); - expect(new URL("example.com/foo/bar/").pathname).toBe("/foo/bar/"); - expect(new URL("example.com/foo/bar/?search=true").search).toBe( - "?search=true" - ); - expect(new URL("example.com/foo/bar/?search=true#fragment").search).toBe( - "?search=true" - ); - expect(new URL("https://example.com").href).toBe("https://example.com/"); - expect(new URL("example.com").hostname).toBe("example.com"); }); }); |