fix(javascript): honor cancellation before evidence publication (#1098)
This commit is contained in:
1 parent
f8e143a3bc
commit
cc0ee2edc6
18 files changed
+1080
-74
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { completeJavaScriptAnalysisSteps } from "./JavaScriptAnalysisControl.js";
|
||||
|
||||
describe("JavaScript cooperative computation lifecycle", () => {
|
||||
it("observes scheduler cancellation and closes abandoned work", async () => {
|
||||
const controller = new AbortController();
|
||||
let released = false;
|
||||
function* work(): Generator<void, number> {
|
||||
try {
|
||||
for (;;) yield;
|
||||
} finally {
|
||||
released = true;
|
||||
}
|
||||
}
|
||||
const cancellation = setImmediate().then(() => controller.abort());
|
||||
await expect(
|
||||
completeJavaScriptAnalysisSteps(work(), controller.signal),
|
||||
).rejects.toMatchObject({ reason: "cancelled" });
|
||||
await cancellation;
|
||||
expect(released).toBe(true);
|
||||
});
|
||||
|
||||
it("does not start pre-cancelled work and preserves completed values", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
let started = false;
|
||||
function* work(): Generator<void, number> {
|
||||
started = true;
|
||||
yield;
|
||||
return 42;
|
||||
}
|
||||
await expect(
|
||||
completeJavaScriptAnalysisSteps(work(), controller.signal),
|
||||
).rejects.toMatchObject({ reason: "cancelled" });
|
||||
expect(started).toBe(false);
|
||||
expect(await completeJavaScriptAnalysisSteps(work())).toBe(42);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user