diff --git a/packages/cli/test/integration/shared/constants.ts b/packages/cli/test/integration/shared/constants.ts index 33189089b5..d68ef00e1e 100644 --- a/packages/cli/test/integration/shared/constants.ts +++ b/packages/cli/test/integration/shared/constants.ts @@ -76,6 +76,11 @@ export const BOOTSTRAP_MYSQL_CONNECTION_NAME: Readonly = '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. */ diff --git a/packages/cli/test/integration/shared/testDb.ts b/packages/cli/test/integration/shared/testDb.ts index 16d4b4f918..552aca823d 100644 --- a/packages/cli/test/integration/shared/testDb.ts +++ b/packages/cli/test/integration/shared/testDb.ts @@ -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); diff --git a/packages/cli/test/setup.ts b/packages/cli/test/setup.ts index 1180a082c5..e0af9209d3 100644 --- a/packages/cli/test/setup.ts +++ b/packages/cli/test/setup.ts @@ -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};`, );