aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/mmap.test.js
blob: 03ce75e8716fec3da251d75f0879bd4f24f8b286 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
});
ass='insertions'>+2 2021-05-13chore: release astro-vscodeGravatar Nate Moore 6-148/+30 2021-05-13Version Packages (#195)Gravatar github-actions[bot] 23-65/+43 2021-05-13Support for import suggestions in the languageserver (#204)Gravatar Matthew Phillips 6-12/+32 2021-05-13Fix Svelte build output (#201)Gravatar Nate Moore 4-8/+14 2021-05-12[wip] Fix CI (#202)Gravatar Drew Powers 28-219/+191 2021-05-11VS Code extension (#197)Gravatar Matthew Phillips 7-20/+182 2021-05-11Fix workflows! (#198)Gravatar Nate Moore 3-2/+4 2021-05-11Add Astro.request.canonicalURL and Astro.site to global (#199)Gravatar Drew Powers 25-98/+234 2021-05-11Fix portfolio example (#196)Gravatar Drew Powers 2-3/+5 2021-05-10fix: build stuck on unhandled promise reject (#191)Gravatar Kevin (Kun) "Kassimo" Qian 2-2/+13 2021-05-10Allow default import component to be renamed based on import statement defaul...Gravatar Kevin (Kun) "Kassimo" Qian 3-8/+30 2021-05-08Add more docs on styling (#186)Gravatar Drew Powers 1-3/+321 2021-05-08Fix running the extension (#181)Gravatar Matthew Phillips 5-11/+37