| 1 | // @effect-diagnostics nodeBuiltinImport:off - memory assertions run in an isolated Node process with explicit GC. |
| 2 | import * as NodeChildProcess from "node:child_process"; |
| 3 | import * as NodeURL from "node:url"; |
| 4 | import * as NodeUtil from "node:util"; |
| 5 | import { expect, it } from "vite-plus/test"; |
| 6 | |
| 7 | const execFile = NodeUtil.promisify(NodeChildProcess.execFile); |
| 8 | |
| 9 | it.each(["prefix", "snapshot", "replay"])( |
| 10 | "releases delivered %s history while RPC subscriptions remain open", |
| 11 | async (mode) => { |
| 12 | const root = NodeURL.fileURLToPath(new URL("../../../", import.meta.url)); |
| 13 | const fixture = NodeURL.fileURLToPath( |
| 14 | new URL("./testkit/RpcInitialMemory.fixture.mjs", import.meta.url), |
| 15 | ); |
| 16 | const { stdout } = await execFile(process.execPath, ["--expose-gc", fixture, root, mode]); |
| 17 | const result = JSON.parse(stdout) as { |
| 18 | checkpoints: ReadonlyArray<{ subscriptions: number; retained: number }>; |
| 19 | }; |
| 20 | expect( |
| 21 | result.checkpoints.map(({ subscriptions, retained }) => ({ subscriptions, retained })), |
| 22 | ).toEqual([ |
| 23 | { subscriptions: 2, retained: 0 }, |
| 24 | { subscriptions: 4, retained: 0 }, |
| 25 | ]); |
| 26 | }, |
| 27 | ); |