Skip to content

Commit 27e363b

Browse files
authored
fix: prevent test worker crash during completion error handling (#305)
1 parent df03e6b commit 27e363b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/durabletask-js/src/testing/in-memory-backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class InMemoryOrchestrationBackend {
310310
): void {
311311
const instance = this.instances.get(instanceId);
312312
if (!instance) {
313-
throw new Error(`Orchestration instance '${instanceId}' not found`);
313+
return; // Instance may have been purged or the backend reset
314314
}
315315

316316
if (instance.completionToken !== completionToken) {

packages/durabletask-js/test/in-memory-backend.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,17 @@ describe("In-Memory Backend", () => {
580580
expect((backend as any).instanceTimers.has(id1)).toBe(false);
581581
});
582582

583+
it("should silently ignore completeOrchestration for purged instances", () => {
584+
// Verifies that completeOrchestration returns silently when the instance
585+
// has been deleted (e.g., via purge or reset), consistent with how
586+
// completeActivity handles missing instances.
587+
588+
// Should not throw — instance simply doesn't exist
589+
expect(() => {
590+
backend.completeOrchestration("nonexistent-instance", 1, []);
591+
}).not.toThrow();
592+
});
593+
583594
it("should allow reusing instance IDs after reset", async () => {
584595
const orchestrator: TOrchestrator = async (_: OrchestrationContext, input: number) => {
585596
return input * 2;

0 commit comments

Comments
 (0)