mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +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'),
|
||||
};
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user