fix(javascript): preserve failure provenance and cleanup ownership
This commit is contained in:
1 parent
957bcfa149
commit
566a9a1551
7 files changed
+175
-69
No files matched your search
@@ -5,6 +5,7 @@ import { completeJavaScriptAnalysisSteps } from "./JavaScriptAnalysisControl.js"
|
||||
describe("JavaScript cooperative computation lifecycle", () => {
|
||||
it("observes scheduler cancellation and closes abandoned work", async () => {
|
||||
const controller = new AbortController();
|
||||
const reason = { request: "caller cancelled computation" };
|
||||
let released = false;
|
||||
function* work(): Generator<void, number> {
|
||||
try {
|
||||
@@ -13,17 +14,18 @@ describe("JavaScript cooperative computation lifecycle", () => {
|
||||
released = true;
|
||||
}
|
||||
}
|
||||
const cancellation = setImmediate().then(() => controller.abort());
|
||||
const cancellation = setImmediate().then(() => controller.abort(reason));
|
||||
await expect(
|
||||
completeJavaScriptAnalysisSteps(work(), controller.signal),
|
||||
).rejects.toMatchObject({ reason: "cancelled" });
|
||||
).rejects.toMatchObject({ reason: "cancelled", cause: reason });
|
||||
await cancellation;
|
||||
expect(released).toBe(true);
|
||||
});
|
||||
|
||||
it("does not start pre-cancelled work and preserves completed values", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const reason = { request: "caller cancelled computation" };
|
||||
controller.abort(reason);
|
||||
let started = false;
|
||||
function* work(): Generator<void, number> {
|
||||
started = true;
|
||||
@@ -32,7 +34,7 @@ describe("JavaScript cooperative computation lifecycle", () => {
|
||||
}
|
||||
await expect(
|
||||
completeJavaScriptAnalysisSteps(work(), controller.signal),
|
||||
).rejects.toMatchObject({ reason: "cancelled" });
|
||||
).rejects.toMatchObject({ reason: "cancelled", cause: reason });
|
||||
expect(started).toBe(false);
|
||||
expect(await completeJavaScriptAnalysisSteps(work())).toBe(42);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user