20 lines
937 B
TypeScript
20 lines
937 B
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { serverLoader } from "../helpers/canvas-download-server-loader";
|
|
|
|
test("release draining includes background work until its original promise settles", async () => {
|
|
const counts: number[] = [];
|
|
const work = serverLoader({
|
|
"node:fs": { writeFileSync: (_path: string, text: string) => counts.push(JSON.parse(text).active), unlinkSync() {} },
|
|
})("lib/observability/active-work.ts");
|
|
let finish!: () => void;
|
|
const original = new Promise<void>(resolve => { finish = resolve; });
|
|
const pending = work.trackRuntimeWork(() => original);
|
|
await work.trackRuntimeWork(async () => "another request");
|
|
expect(counts).toEqual([1, 2, 1]);
|
|
finish();
|
|
await pending;
|
|
expect(counts).toEqual([1, 2, 1, 0]);
|
|
await expect(work.trackRuntimeWork(async () => { throw new Error("expected failure"); })).rejects.toThrow("expected failure");
|
|
expect(counts.at(-1)).toBe(0);
|
|
});
|