mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
fix: Check for status when canceling execution (#16690)
This commit is contained in:
@@ -948,27 +948,31 @@ describe('useRunWorkflow({ router })', () => {
|
|||||||
createdAt: new Date('2025-04-01T00:00:00.000Z'),
|
createdAt: new Date('2025-04-01T00:00:00.000Z'),
|
||||||
};
|
};
|
||||||
const markStoppedSpy = vi.spyOn(workflowsStore, 'markExecutionAsStopped');
|
const markStoppedSpy = vi.spyOn(workflowsStore, 'markExecutionAsStopped');
|
||||||
|
const getExecutionSpy = vi.spyOn(workflowsStore, 'getExecution');
|
||||||
|
|
||||||
workflowsStore.workflowExecutionData = executionData;
|
|
||||||
workflowsStore.activeWorkflows = ['test-wf-id'];
|
workflowsStore.activeWorkflows = ['test-wf-id'];
|
||||||
workflowsStore.setActiveExecutionId('test-exec-id');
|
workflowsStore.setActiveExecutionId('test-exec-id');
|
||||||
|
|
||||||
|
getExecutionSpy.mockResolvedValue(executionData);
|
||||||
|
|
||||||
// Exercise - don't wait for returned promise to resolve
|
// Exercise - don't wait for returned promise to resolve
|
||||||
void runWorkflowComposable.stopCurrentExecution();
|
void runWorkflowComposable.stopCurrentExecution();
|
||||||
|
|
||||||
// Assert that markExecutionAsStopped() isn't called yet after a simulated delay
|
// Assert that markExecutionAsStopped() isn't called yet after a simulated delay
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||||
expect(markStoppedSpy).not.toHaveBeenCalled();
|
expect(markStoppedSpy).not.toHaveBeenCalled();
|
||||||
|
expect(getExecutionSpy).toHaveBeenCalledWith('test-exec-id');
|
||||||
|
|
||||||
// Simulated executionFinished event
|
// Simulated executionFinished event
|
||||||
workflowsStore.workflowExecutionData = {
|
getExecutionSpy.mockResolvedValue({
|
||||||
...executionData,
|
...executionData,
|
||||||
status: 'canceled',
|
status: 'canceled',
|
||||||
stoppedAt: new Date('2025-04-01T00:00:99.000Z'),
|
stoppedAt: new Date('2025-04-01T00:00:99.000Z'),
|
||||||
};
|
});
|
||||||
|
|
||||||
// Assert that markExecutionAsStopped() is called eventually
|
// Assert that markExecutionAsStopped() is called eventually
|
||||||
await waitFor(() => expect(markStoppedSpy).toHaveBeenCalled());
|
await waitFor(() => expect(markStoppedSpy).toHaveBeenCalled());
|
||||||
|
expect(getExecutionSpy).toHaveBeenCalledWith('test-exec-id');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -504,7 +504,8 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
|
|||||||
// Wait for websocket event to update the execution status to 'canceled'
|
// Wait for websocket event to update the execution status to 'canceled'
|
||||||
const markedAsStopped = await retry(
|
const markedAsStopped = await retry(
|
||||||
async () => {
|
async () => {
|
||||||
if (workflowsStore.workflowExecutionData?.status !== 'running') {
|
const execution = await workflowsStore.getExecution(executionId);
|
||||||
|
if (!['running', 'waiting'].includes(execution?.status as string)) {
|
||||||
workflowsStore.markExecutionAsStopped();
|
workflowsStore.markExecutionAsStopped();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user