Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Refactor DB tests (no-changelog) #7292

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ version: '3.9'

services:
mysql:
image: mysql:5.7-debian
image: mysql:5.7
environment:
- MYSQL_DATABASE=n8n
- MYSQL_ROOT_PASSWORD=password
ports:
- 3306:3306
ulimits:
nproc: 65535
nofile:
soft: 26677
hard: 46677

postgres:
image: postgres:11
restart: always
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=root
Expand Down
86 changes: 70 additions & 16 deletions .github/workflows/ci-postgres-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,99 @@ on:
- packages/cli/src/databases/migrations/**

jobs:
test:
build:
name: Install & Build
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: pnpm/[email protected]
- uses: actions/[email protected]
with:
node-version: 18.x
cache: 'pnpm'
- run: pnpm install --frozen-lockfile

- name: Build Backend
run: pnpm --filter @n8n/client-oauth2 --filter n8n-workflow --filter n8n-core --filter n8n build

timeout-minutes: 60
- name: Cache build artifacts
uses: actions/cache/[email protected]
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests

mysql:
name: MySQL
runs-on: ubuntu-latest
needs: build
timeout-minutes: 20
env:
DB_MYSQLDB_PASSWORD: password
DB_POSTGRESDB_PASSWORD: password

steps:
- uses: actions/[email protected]

- uses: pnpm/[email protected]

- uses: actions/[email protected]
with:
node-version: 18.x
cache: 'pnpm'
- run: pnpm install --frozen-lockfile

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Restore cached build artifacts
uses: actions/cache/[email protected]
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests

- name: Start MySQL & Postgres
uses: isbang/compose-action@v1.3.2
- name: Start MySQL
uses: isbang/compose-action@v1.5.1
with:
compose-file: ./.github/docker-compose.yml

- name: Build Core, Workflow, and CLI
run: pnpm --filter @n8n/client-oauth2 --filter n8n-workflow --filter n8n-core --filter n8n build
services: |
mysql

- name: Test MySQL
working-directory: packages/cli
run: DB_TABLE_PREFIX=test_ pnpm test:mysql
run: DB_TABLE_PREFIX=test_ pnpm test:mysql --runInBand

postgres:
name: Postgres
runs-on: ubuntu-latest
needs: build
timeout-minutes: 20
env:
DB_POSTGRESDB_PASSWORD: password
steps:
- uses: actions/[email protected]
- uses: pnpm/[email protected]
- uses: actions/[email protected]
with:
node-version: 18.x
cache: 'pnpm'
- run: pnpm install --frozen-lockfile

- name: Restore cached build artifacts
uses: actions/cache/[email protected]
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests

- name: Start Postgres
uses: isbang/[email protected]
with:
compose-file: ./.github/docker-compose.yml
services: |
postgres

- name: Test Postgres
working-directory: packages/cli
run: DB_POSTGRESDB_SCHEMA=alt_schema DB_TABLE_PREFIX=test_ pnpm test:postgres
run: DB_POSTGRESDB_SCHEMA=alt_schema DB_TABLE_PREFIX=test_ pnpm test:postgres --runInBand

- name: Notify Slack on master failure
notify-on-failure:
name: Notify Slack on failure
runs-on: ubuntu-latest
needs: [mysql, postgres]
steps:
- name: Notify Slack on failure
uses: act10ns/[email protected]
if: failure() && github.ref == 'refs/heads/master'
with:
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { compilerOptions } = require('./tsconfig.json');

/** @type {import('ts-jest').TsJestGlobalOptions} */
const tsJestOptions = {
isolatedModules: true,
tsconfig: {
Expand Down
32 changes: 14 additions & 18 deletions packages/cli/test/integration/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ describe('POST /credentials', () => {
});

test('should fail with invalid inputs', async () => {
await Promise.all(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using await Promise.all( is somehow causing DB connection resets, leading to failing tests.
Not sure why that is, but switched to a for loop to unblock the CI.

INVALID_PAYLOADS.map(async (invalidPayload) => {
const response = await authOwnerAgent.post('/credentials').send(invalidPayload);
expect(response.statusCode).toBe(400);
}),
);
for (const invalidPayload of INVALID_PAYLOADS) {
const response = await authOwnerAgent.post('/credentials').send(invalidPayload);
expect(response.statusCode).toBe(400);
}
});

test('should fail with missing encryption key', async () => {
Expand Down Expand Up @@ -370,18 +368,16 @@ describe('PATCH /credentials/:id', () => {
test('should fail with invalid inputs', async () => {
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });

await Promise.all(
INVALID_PAYLOADS.map(async (invalidPayload) => {
const response = await authOwnerAgent
.patch(`/credentials/${savedCredential.id}`)
.send(invalidPayload);

if (response.statusCode === 500) {
console.log(response.statusCode, response.body);
}
expect(response.statusCode).toBe(400);
}),
);
for (const invalidPayload of INVALID_PAYLOADS) {
const response = await authOwnerAgent
.patch(`/credentials/${savedCredential.id}`)
.send(invalidPayload);

if (response.statusCode === 500) {
console.log(response.statusCode, response.body);
}
expect(response.statusCode).toBe(400);
}
});

test('should fail if cred not found', async () => {
Expand Down
Loading