🧪 Add DB init timeout

This commit is contained in:
Iván Ovejero 2022-06-30 14:06:16 +02:00
parent de55fdb625
commit e6347e34ca
3 changed files with 20 additions and 3 deletions

View file

@ -76,6 +76,11 @@ export const BOOTSTRAP_MYSQL_CONNECTION_NAME: Readonly<string> = 'n8n_bs_mysql';
*/
export const SMTP_TEST_TIMEOUT = 30_000;
/**
* Timeout (in milliseconds) to account for DB being slow to initialize.
*/
export const DB_INITIALIZATION_TIMEOUT = 30_000;
/**
* Mapping tables having no entity representation.
*/

View file

@ -8,6 +8,7 @@ import config from '../../../config';
import {
BOOTSTRAP_MYSQL_CONNECTION_NAME,
BOOTSTRAP_POSTGRES_CONNECTION_NAME,
DB_INITIALIZATION_TIMEOUT,
MAPPING_TABLES,
MAPPING_TABLES_TO_CLEAR,
} from './constants';
@ -38,6 +39,8 @@ export async function init() {
const dbType = config.getEnv('database.type');
if (dbType === 'sqlite') {
jest.setTimeout(DB_INITIALIZATION_TIMEOUT);
// no bootstrap connection required
const testDbName = `n8n_test_sqlite_${randomString(6, 10)}_${Date.now()}`;
await Db.init(getSqliteOptions({ name: testDbName }));
@ -47,6 +50,8 @@ export async function init() {
}
if (dbType === 'postgresdb') {
jest.setTimeout(DB_INITIALIZATION_TIMEOUT);
let bootstrapPostgres;
const pgOptions = getBootstrapPostgresOptions();
@ -92,6 +97,8 @@ export async function init() {
}
if (dbType === 'mysqldb') {
// initialization timeout in test/setup.ts
const bootstrapMysql = await createConnection(getBootstrapMySqlOptions());
const testDbName = `mysql_${randomString(6, 10)}_${Date.now()}_n8n_test`;
@ -147,7 +154,9 @@ async function truncateMappingTables(
if (dbType === 'sqlite') {
const promises = mappingTables.map((tableName) =>
testDb.query(`DELETE FROM ${tableName}; DELETE FROM sqlite_sequence WHERE name=${tableName};`),
testDb.query(
`DELETE FROM ${tableName}; DELETE FROM sqlite_sequence WHERE name=${tableName};`,
),
);
return Promise.all(promises);

View file

@ -2,7 +2,10 @@ import { exec as callbackExec } from 'child_process';
import { promisify } from 'util';
import config from '../config';
import { BOOTSTRAP_MYSQL_CONNECTION_NAME } from './integration/shared/constants';
import {
BOOTSTRAP_MYSQL_CONNECTION_NAME,
DB_INITIALIZATION_TIMEOUT,
} from './integration/shared/constants';
const exec = promisify(callbackExec);
@ -17,7 +20,7 @@ if (dbType === 'mysqldb') {
(async () => {
try {
jest.setTimeout(30000); // 30 seconds for DB initialization
jest.setTimeout(DB_INITIALIZATION_TIMEOUT);
await exec(
`echo "CREATE DATABASE IF NOT EXISTS ${BOOTSTRAP_MYSQL_CONNECTION_NAME}" | mysql -h ${host} -u ${username} ${passwordSegment}; USE ${BOOTSTRAP_MYSQL_CONNECTION_NAME};`,
);