Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/durabletask-js/src/testing/in-memory-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export class InMemoryOrchestrationBackend {
reset(): void {
this.instances.clear();
this.orchestrationQueue.length = 0;
this.orchestrationQueueSet.clear();
this.activityQueue.length = 0;
for (const waiters of this.stateWaiters.values()) {
for (const waiter of waiters) {
Expand Down
22 changes: 22 additions & 0 deletions packages/durabletask-js/test/in-memory-backend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,26 @@ describe("In-Memory Backend", () => {
const state = await client.getOrchestrationState(id);
expect(state).toBeUndefined();
});

it("should allow reusing instance IDs after reset", async () => {
const orchestrator: TOrchestrator = async (_: OrchestrationContext, input: number) => {
return input * 2;
};

// Create an orchestration without starting the worker, so it stays in the queue
const instanceId = "reuse-test-id";
backend.createInstance(instanceId, getName(orchestrator), JSON.stringify(10));

// Reset while the orchestration is still queued (not yet processed)
backend.reset();

// Now create a new orchestration with the same instance ID and process it
worker.addOrchestrator(orchestrator);
await worker.start();

await client.scheduleNewOrchestration(orchestrator, 21, instanceId);
const state = await client.waitForOrchestrationCompletion(instanceId, true, 10);
expect(state?.runtimeStatus).toEqual(OrchestrationStatus.COMPLETED);
expect(state?.serializedOutput).toEqual(JSON.stringify(42));
});
});
Loading