aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/mmap.test.js
diff options
context:
space:
mode:
authorGravatar evan <github@evan.lol> 2022-03-27 05:38:39 -0400
committerGravatar GitHub <noreply@github.com> 2022-03-27 02:38:39 -0700
commit0132b7164e956d56bf74dd8c45ad4cf90769961b (patch)
tree0dce8a77a616830b8a6e75d1d5505c2bb180e734 /integration/bunjs-only-snippets/mmap.test.js
parent2fc881540b680f28486bd0f597eb3a1262c2ea8b (diff)
downloadbun-0132b7164e956d56bf74dd8c45ad4cf90769961b.tar.gz
bun-0132b7164e956d56bf74dd8c45ad4cf90769961b.tar.zst
bun-0132b7164e956d56bf74dd8c45ad4cf90769961b.zip
Bun.mmap() (#134)
* Bun.mmap() * nitpicks
Diffstat (limited to 'integration/bunjs-only-snippets/mmap.test.js')
-rw-r--r--integration/bunjs-only-snippets/mmap.test.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/mmap.test.js b/integration/bunjs-only-snippets/mmap.test.js
new file mode 100644
index 000000000..03ce75e87
--- /dev/null
+++ b/integration/bunjs-only-snippets/mmap.test.js
@@ -0,0 +1,49 @@
+import { describe, it, expect } from "bun:test";
+
+const path = `/tmp/bun-mmap-test_${Math.random()}.txt`;
+
+await Bun.write(path, "hello");
+
+it("mmap finalizer", async () => {
+ let map = Bun.mmap(path);
+ const map2 = Bun.mmap(path);
+
+ 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 sync", async () => {
+ const map = Bun.mmap(path);
+ const map2 = Bun.mmap(path);
+
+ const old = map[0];
+
+ 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");
+});
+
+it("mmap private", () => {
+ const map = Bun.mmap(path, { shared: true });
+ const map2 = Bun.mmap(path, { shared: false });
+
+ const old = map[0];
+
+ map2[0] = 0;
+ expect(map2[0]).toBe(0);
+ expect(map[0]).toBe(old);
+}); \ No newline at end of file