fix: Check for status when canceling execution (#16690)

This commit is contained in:
Michael Kret
2025-06-26 11:00:14 +03:00
committed by GitHub
parent e6515a2a74
commit 901e034196
2 changed files with 9 additions and 4 deletions

View File

@@ -948,27 +948,31 @@ describe('useRunWorkflow({ router })', () => {
createdAt: new Date('2025-04-01T00:00:00.000Z'),
};
const markStoppedSpy = vi.spyOn(workflowsStore, 'markExecutionAsStopped');
const getExecutionSpy = vi.spyOn(workflowsStore, 'getExecution');
workflowsStore.workflowExecutionData = executionData;
workflowsStore.activeWorkflows = ['test-wf-id'];
workflowsStore.setActiveExecutionId('test-exec-id');
getExecutionSpy.mockResolvedValue(executionData);
// Exercise - don't wait for returned promise to resolve
void runWorkflowComposable.stopCurrentExecution();
// Assert that markExecutionAsStopped() isn't called yet after a simulated delay
await new Promise((resolve) => setTimeout(resolve, 10));
expect(markStoppedSpy).not.toHaveBeenCalled();
expect(getExecutionSpy).toHaveBeenCalledWith('test-exec-id');
// Simulated executionFinished event
workflowsStore.workflowExecutionData = {
getExecutionSpy.mockResolvedValue({
...executionData,
status: 'canceled',
stoppedAt: new Date('2025-04-01T00:00:99.000Z'),
};
});
// Assert that markExecutionAsStopped() is called eventually
await waitFor(() => expect(markStoppedSpy).toHaveBeenCalled());
expect(getExecutionSpy).toHaveBeenCalledWith('test-exec-id');
});
});

View File

@@ -504,7 +504,8 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
// Wait for websocket event to update the execution status to 'canceled'
const markedAsStopped = await retry(
async () => {
if (workflowsStore.workflowExecutionData?.status !== 'running') {
const execution = await workflowsStore.getExecution(executionId);
if (!['running', 'waiting'].includes(execution?.status as string)) {
workflowsStore.markExecutionAsStopped();
return true;
}