diff options
Diffstat (limited to 'integration/bunjs-only-snippets/mmap.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/mmap.test.js | 94 |
1 files changed, 57 insertions, 37 deletions
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(); + }); }); |