From 58be4abc311ead732f74da6e4a4446392f361882 Mon Sep 17 00:00:00 2001 From: Dries Augustyns Date: Wed, 27 May 2026 18:08:13 +0200 Subject: [PATCH] tests: prevent race condition by inserting RUNNING execution directly --- .../src/services/__tests__/WorkflowService.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/api/src/services/__tests__/WorkflowService.test.ts b/apps/api/src/services/__tests__/WorkflowService.test.ts index 7282bce..a45a26a 100644 --- a/apps/api/src/services/__tests__/WorkflowService.test.ts +++ b/apps/api/src/services/__tests__/WorkflowService.test.ts @@ -758,8 +758,18 @@ describe('WorkflowService', () => { }); const contact = await factories.createContact({projectId}); - // Start first execution (still running) - await WorkflowService.startExecution(projectId, workflow.id, contact.id); + // Insert a RUNNING execution directly to avoid racing with the background + // step processor that startExecution kicks off (a trigger-only workflow can + // transition to COMPLETED before the second call observes it as RUNNING). + const triggerStep = workflow.steps.find(step => step.type === WorkflowStepType.TRIGGER); + await prisma.workflowExecution.create({ + data: { + workflowId: workflow.id, + contactId: contact.id, + status: WorkflowExecutionStatus.RUNNING, + currentStepId: triggerStep?.id, + }, + }); // Second execution should fail (first still running) await expect(WorkflowService.startExecution(projectId, workflow.id, contact.id)).rejects.toThrow(