ci(core): Reduce memory usage in tests (part-1) (no-changelog) (#7654)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-11-08 16:29:39 +01:00
committed by GitHub
parent 6a53c2a375
commit 0346b211a7
58 changed files with 1223 additions and 1189 deletions

View File

@@ -5,6 +5,19 @@ import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
import { randomApiKey } from '../shared/random';
import * as utils from '../shared/utils/';
import * as testDb from '../shared/testDb';
import { getGlobalMemberRole, getGlobalOwnerRole } from '../shared/db/roles';
import { createUser } from '../shared/db/users';
import {
createManyWorkflows,
createWorkflow,
shareWorkflowWithUsers,
} from '../shared/db/workflows';
import {
createErrorExecution,
createManyExecutions,
createSuccessfulExecution,
createWaitingExecution,
} from '../shared/db/executions';
let owner: User;
let user1: User;
@@ -17,11 +30,11 @@ let workflowRunner: ActiveWorkflowRunner;
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
beforeAll(async () => {
const globalOwnerRole = await testDb.getGlobalOwnerRole();
const globalUserRole = await testDb.getGlobalMemberRole();
owner = await testDb.createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
user1 = await testDb.createUser({ globalRole: globalUserRole, apiKey: randomApiKey() });
user2 = await testDb.createUser({ globalRole: globalUserRole, apiKey: randomApiKey() });
const globalOwnerRole = await getGlobalOwnerRole();
const globalUserRole = await getGlobalMemberRole();
owner = await createUser({ globalRole: globalOwnerRole, apiKey: randomApiKey() });
user1 = await createUser({ globalRole: globalUserRole, apiKey: randomApiKey() });
user2 = await createUser({ globalRole: globalUserRole, apiKey: randomApiKey() });
// TODO: mock BinaryDataService instead
await utils.initBinaryDataService();
@@ -62,9 +75,9 @@ describe('GET /executions/:id', () => {
test('should fail due to invalid API Key', testWithAPIKey('get', '/executions/1', 'abcXYZ'));
test('owner should be able to get an execution owned by him', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const workflow = await createWorkflow({}, owner);
const execution = await testDb.createSuccessfulExecution(workflow);
const execution = await createSuccessfulExecution(workflow);
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
@@ -94,8 +107,8 @@ describe('GET /executions/:id', () => {
});
test('owner should be able to read executions of other users', async () => {
const workflow = await testDb.createWorkflow({}, user1);
const execution = await testDb.createSuccessfulExecution(workflow);
const workflow = await createWorkflow({}, user1);
const execution = await createSuccessfulExecution(workflow);
const response = await authOwnerAgent.get(`/executions/${execution.id}`);
@@ -103,8 +116,8 @@ describe('GET /executions/:id', () => {
});
test('member should be able to fetch his own executions', async () => {
const workflow = await testDb.createWorkflow({}, user1);
const execution = await testDb.createSuccessfulExecution(workflow);
const workflow = await createWorkflow({}, user1);
const execution = await createSuccessfulExecution(workflow);
const response = await authUser1Agent.get(`/executions/${execution.id}`);
@@ -112,9 +125,9 @@ describe('GET /executions/:id', () => {
});
test('member should not get an execution of another user without the workflow being shared', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const workflow = await createWorkflow({}, owner);
const execution = await testDb.createSuccessfulExecution(workflow);
const execution = await createSuccessfulExecution(workflow);
const response = await authUser1Agent.get(`/executions/${execution.id}`);
@@ -122,11 +135,11 @@ describe('GET /executions/:id', () => {
});
test('member should be able to fetch executions of workflows shared with him', async () => {
const workflow = await testDb.createWorkflow({}, user1);
const workflow = await createWorkflow({}, user1);
const execution = await testDb.createSuccessfulExecution(workflow);
const execution = await createSuccessfulExecution(workflow);
await testDb.shareWorkflowWithUsers(workflow, [user2]);
await shareWorkflowWithUsers(workflow, [user2]);
const response = await authUser2Agent.get(`/executions/${execution.id}`);
@@ -140,8 +153,8 @@ describe('DELETE /executions/:id', () => {
test('should fail due to invalid API Key', testWithAPIKey('delete', '/executions/1', 'abcXYZ'));
test('should delete an execution', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const execution = await testDb.createSuccessfulExecution(workflow);
const workflow = await createWorkflow({}, owner);
const execution = await createSuccessfulExecution(workflow);
const response = await authOwnerAgent.delete(`/executions/${execution.id}`);
@@ -179,11 +192,11 @@ describe('GET /executions', () => {
test('should fail due to invalid API Key', testWithAPIKey('get', '/executions', 'abcXYZ'));
test('should retrieve all successful executions', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const workflow = await createWorkflow({}, owner);
const successfulExecution = await testDb.createSuccessfulExecution(workflow);
const successfulExecution = await createSuccessfulExecution(workflow);
await testDb.createErrorExecution(workflow);
await createErrorExecution(workflow);
const response = await authOwnerAgent.get('/executions').query({
status: 'success',
@@ -219,13 +232,13 @@ describe('GET /executions', () => {
// failing on Postgres and MySQL - ref: https://github.com/n8n-io/n8n/pull/3834
// eslint-disable-next-line n8n-local-rules/no-skipped-tests
test.skip('should paginate two executions', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const workflow = await createWorkflow({}, owner);
const firstSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
const firstSuccessfulExecution = await createSuccessfulExecution(workflow);
const secondSuccessfulExecution = await testDb.createSuccessfulExecution(workflow);
const secondSuccessfulExecution = await createSuccessfulExecution(workflow);
await testDb.createErrorExecution(workflow);
await createErrorExecution(workflow);
const firstExecutionResponse = await authOwnerAgent.get('/executions').query({
status: 'success',
@@ -275,11 +288,11 @@ describe('GET /executions', () => {
});
test('should retrieve all error executions', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const workflow = await createWorkflow({}, owner);
await testDb.createSuccessfulExecution(workflow);
await createSuccessfulExecution(workflow);
const errorExecution = await testDb.createErrorExecution(workflow);
const errorExecution = await createErrorExecution(workflow);
const response = await authOwnerAgent.get('/executions').query({
status: 'error',
@@ -313,13 +326,13 @@ describe('GET /executions', () => {
});
test('should return all waiting executions', async () => {
const workflow = await testDb.createWorkflow({}, owner);
const workflow = await createWorkflow({}, owner);
await testDb.createSuccessfulExecution(workflow);
await createSuccessfulExecution(workflow);
await testDb.createErrorExecution(workflow);
await createErrorExecution(workflow);
const waitingExecution = await testDb.createWaitingExecution(workflow);
const waitingExecution = await createWaitingExecution(workflow);
const response = await authOwnerAgent.get('/executions').query({
status: 'waiting',
@@ -353,14 +366,10 @@ describe('GET /executions', () => {
});
test('should retrieve all executions of specific workflow', async () => {
const [workflow, workflow2] = await testDb.createManyWorkflows(2, {}, owner);
const [workflow, workflow2] = await createManyWorkflows(2, {}, owner);
const savedExecutions = await testDb.createManyExecutions(
2,
workflow,
testDb.createSuccessfulExecution,
);
await testDb.createManyExecutions(2, workflow2, testDb.createSuccessfulExecution);
const savedExecutions = await createManyExecutions(2, workflow, createSuccessfulExecution);
await createManyExecutions(2, workflow2, createSuccessfulExecution);
const response = await authOwnerAgent.get('/executions').query({
workflowId: workflow.id,
@@ -396,21 +405,13 @@ describe('GET /executions', () => {
});
test('owner should retrieve all executions regardless of ownership', async () => {
const [firstWorkflowForUser1, secondWorkflowForUser1] = await testDb.createManyWorkflows(
2,
{},
user1,
);
await testDb.createManyExecutions(2, firstWorkflowForUser1, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser1, testDb.createSuccessfulExecution);
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);
await createManyExecutions(2, secondWorkflowForUser1, createSuccessfulExecution);
const [firstWorkflowForUser2, secondWorkflowForUser2] = await testDb.createManyWorkflows(
2,
{},
user2,
);
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);
const [firstWorkflowForUser2, secondWorkflowForUser2] = await createManyWorkflows(2, {}, user2);
await createManyExecutions(2, firstWorkflowForUser2, createSuccessfulExecution);
await createManyExecutions(2, secondWorkflowForUser2, createSuccessfulExecution);
const response = await authOwnerAgent.get('/executions');
@@ -420,21 +421,13 @@ describe('GET /executions', () => {
});
test('member should not see executions of workflows not shared with him', async () => {
const [firstWorkflowForUser1, secondWorkflowForUser1] = await testDb.createManyWorkflows(
2,
{},
user1,
);
await testDb.createManyExecutions(2, firstWorkflowForUser1, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser1, testDb.createSuccessfulExecution);
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);
await createManyExecutions(2, secondWorkflowForUser1, createSuccessfulExecution);
const [firstWorkflowForUser2, secondWorkflowForUser2] = await testDb.createManyWorkflows(
2,
{},
user2,
);
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);
const [firstWorkflowForUser2, secondWorkflowForUser2] = await createManyWorkflows(2, {}, user2);
await createManyExecutions(2, firstWorkflowForUser2, createSuccessfulExecution);
await createManyExecutions(2, secondWorkflowForUser2, createSuccessfulExecution);
const response = await authUser1Agent.get('/executions');
@@ -444,23 +437,15 @@ describe('GET /executions', () => {
});
test('member should also see executions of workflows shared with him', async () => {
const [firstWorkflowForUser1, secondWorkflowForUser1] = await testDb.createManyWorkflows(
2,
{},
user1,
);
await testDb.createManyExecutions(2, firstWorkflowForUser1, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser1, testDb.createSuccessfulExecution);
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);
await createManyExecutions(2, secondWorkflowForUser1, createSuccessfulExecution);
const [firstWorkflowForUser2, secondWorkflowForUser2] = await testDb.createManyWorkflows(
2,
{},
user2,
);
await testDb.createManyExecutions(2, firstWorkflowForUser2, testDb.createSuccessfulExecution);
await testDb.createManyExecutions(2, secondWorkflowForUser2, testDb.createSuccessfulExecution);
const [firstWorkflowForUser2, secondWorkflowForUser2] = await createManyWorkflows(2, {}, user2);
await createManyExecutions(2, firstWorkflowForUser2, createSuccessfulExecution);
await createManyExecutions(2, secondWorkflowForUser2, createSuccessfulExecution);
await testDb.shareWorkflowWithUsers(firstWorkflowForUser2, [user1]);
await shareWorkflowWithUsers(firstWorkflowForUser2, [user1]);
const response = await authUser1Agent.get('/executions');