|
| 1 | +import { before, after, fs, sudo } from "./setup"; |
| 2 | +import { readFile, writeFile, unlink } from "fs/promises"; |
| 3 | +import { join } from "path"; |
| 4 | +import { wait } from "@cocalc/backend/conat/test/util"; |
| 5 | +import { randomBytes } from "crypto"; |
| 6 | + |
| 7 | +beforeAll(before); |
| 8 | +//const log = console.log; |
| 9 | +const log = (..._args) => {}; |
| 10 | + |
| 11 | +describe("stress test creating many snapshots", () => { |
| 12 | + let vol; |
| 13 | + it("creates a volume and write a file to it", async () => { |
| 14 | + vol = await fs.subvolume("stress"); |
| 15 | + }); |
| 16 | + |
| 17 | + const count = 25; |
| 18 | + it(`create file and snapshot the volume ${count} times`, async () => { |
| 19 | + const snaps: string[] = []; |
| 20 | + const start = Date.now(); |
| 21 | + for (let i = 0; i < count; i++) { |
| 22 | + await writeFile(join(vol.path, `${i}.txt`), "world"); |
| 23 | + await vol.createSnapshot(`snap${i}`); |
| 24 | + snaps.push(`snap${i}`); |
| 25 | + } |
| 26 | + log( |
| 27 | + `created ${Math.round((count / (Date.now() - start)) * 1000)} snapshots per second in serial`, |
| 28 | + ); |
| 29 | + snaps.sort(); |
| 30 | + expect(await vol.snapshots()).toEqual(snaps); |
| 31 | + }); |
| 32 | + |
| 33 | + it(`delete our ${count} snapshots`, async () => { |
| 34 | + for (let i = 0; i < count; i++) { |
| 35 | + await vol.deleteSnapshot(`snap${i}`); |
| 36 | + } |
| 37 | + expect(await vol.snapshots()).toEqual([]); |
| 38 | + }); |
| 39 | +}); |
| 40 | + |
| 41 | +afterAll(after); |
0 commit comments