fix(core): Make execution and its data creation atomic (#11392)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-10-24 16:07:26 +02:00
committed by GitHub
parent 0d0bd2932e
commit ed30d43236
3 changed files with 71 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import { GlobalConfig } from '@n8n/config';
import Container from 'typedi';
import { ExecutionDataRepository } from '@/databases/repositories/execution-data.repository';
@@ -54,5 +55,38 @@ describe('ExecutionRepository', () => {
});
expect(executionData?.data).toEqual('[{"resultData":"1"},{}]');
});
it('should not create execution if execution data insert fails', async () => {
const { type: dbType, sqlite: sqliteConfig } = Container.get(GlobalConfig).database;
// Do not run this test for the legacy sqlite driver
if (dbType === 'sqlite' && sqliteConfig.poolSize === 0) return;
const executionRepo = Container.get(ExecutionRepository);
const executionDataRepo = Container.get(ExecutionDataRepository);
const workflow = await createWorkflow({ settings: { executionOrder: 'v1' } });
jest
.spyOn(executionDataRepo, 'createExecutionDataForExecution')
.mockRejectedValueOnce(new Error());
await expect(
async () =>
await executionRepo.createNewExecution({
workflowId: workflow.id,
data: {
//@ts-expect-error This is not needed for tests
resultData: {},
},
workflowData: workflow,
mode: 'manual',
startedAt: new Date(),
status: 'new',
finished: false,
}),
).rejects.toThrow();
const executionEntities = await executionRepo.find();
expect(executionEntities).toBeEmptyArray();
});
});
});