Skip to content

Commit fe09e4f

Browse files
authored
fix: clear orchestrationQueueSet in InMemoryOrchestrationBackend.reset() (#133)
1 parent cd093e6 commit fe09e4f

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ export class InMemoryOrchestrationBackend {
382382
reset(): void {
383383
this.instances.clear();
384384
this.orchestrationQueue.length = 0;
385+
this.orchestrationQueueSet.clear();
385386
this.activityQueue.length = 0;
386387
for (const waiters of this.stateWaiters.values()) {
387388
for (const waiter of waiters) {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,26 @@ describe("In-Memory Backend", () => {
286286
const state = await client.getOrchestrationState(id);
287287
expect(state).toBeUndefined();
288288
});
289+
290+
it("should allow reusing instance IDs after reset", async () => {
291+
const orchestrator: TOrchestrator = async (_: OrchestrationContext, input: number) => {
292+
return input * 2;
293+
};
294+
295+
// Create an orchestration without starting the worker, so it stays in the queue
296+
const instanceId = "reuse-test-id";
297+
backend.createInstance(instanceId, getName(orchestrator), JSON.stringify(10));
298+
299+
// Reset while the orchestration is still queued (not yet processed)
300+
backend.reset();
301+
302+
// Now create a new orchestration with the same instance ID and process it
303+
worker.addOrchestrator(orchestrator);
304+
await worker.start();
305+
306+
await client.scheduleNewOrchestration(orchestrator, 21, instanceId);
307+
const state = await client.waitForOrchestrationCompletion(instanceId, true, 10);
308+
expect(state?.runtimeStatus).toEqual(OrchestrationStatus.COMPLETED);
309+
expect(state?.serializedOutput).toEqual(JSON.stringify(42));
310+
});
289311
});

0 commit comments

Comments
 (0)