Skip to content

Commit

Permalink
fix(editor): Fix partial executions not working due to broken push me…
Browse files Browse the repository at this point in the history
…ssage queue and race conditions (#11798)
  • Loading branch information
despairblue authored Nov 20, 2024
1 parent 8fbad74 commit b05d435
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 29 additions & 1 deletion packages/editor-ui/src/composables/usePushConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRouter } from 'vue-router';
import { createPinia, setActivePinia } from 'pinia';
import type { PushMessage, PushPayload } from '@n8n/api-types';
import { mock } from 'vitest-mock-extended';
import type { WorkflowOperationError } from 'n8n-workflow';
import type { ITaskData, WorkflowOperationError } from 'n8n-workflow';

import { usePushConnection } from '@/composables/usePushConnection';
import { usePushConnectionStore } from '@/stores/pushConnection.store';
Expand Down Expand Up @@ -61,6 +61,7 @@ describe('usePushConnection()', () => {

afterEach(() => {
vi.restoreAllMocks();
pushConnection.pushMessageQueue.value = [];
});

describe('initialize()', () => {
Expand Down Expand Up @@ -221,5 +222,32 @@ describe('usePushConnection()', () => {
expect(spy).toHaveBeenCalledWith(executionId);
});
});

describe('nodeExecuteAfter', async () => {
it("enqueues messages if we don't have the active execution id yet", async () => {
uiStore.isActionActive.workflowRunning = true;
const event: PushMessage = {
type: 'nodeExecuteAfter',
data: {
executionId: '1',
nodeName: 'foo',
data: {} as ITaskData,
},
};

expect(pushConnection.retryTimeout.value).toBeNull();
expect(pushConnection.pushMessageQueue.value.length).toBe(0);

const result = await pushConnection.pushMessageReceived(event);

expect(result).toBe(false);
expect(pushConnection.pushMessageQueue.value).toHaveLength(1);
expect(pushConnection.pushMessageQueue.value).toContainEqual({
message: event,
retriesLeft: 5,
});
expect(pushConnection.retryTimeout).not.toBeNull();
});
});
});
});
4 changes: 2 additions & 2 deletions packages/editor-ui/src/composables/usePushConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function usePushConnection({ router }: { router: ReturnType<typeof useRou
// The data is not for the currently active execution or
// we do not have the execution id yet.
if (isRetry !== true) {
queuePushMessage(event as unknown as PushMessage, retryAttempts);
queuePushMessage(receivedData, retryAttempts);
}
return false;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ export function usePushConnection({ router }: { router: ReturnType<typeof useRou
// The workflow which did finish execution did either not get started
// by this session or we do not have the execution id yet.
if (isRetry !== true) {
queuePushMessage(event as unknown as PushMessage, retryAttempts);
queuePushMessage(receivedData, retryAttempts);
}
return false;
}
Expand Down

0 comments on commit b05d435

Please sign in to comment.