diff --git a/.changeset/wet-snakes-hide.md b/.changeset/wet-snakes-hide.md new file mode 100644 index 0000000000000..21e160100445d --- /dev/null +++ b/.changeset/wet-snakes-hide.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +tests(integration-tests): Add integration test suite for database options diff --git a/integration-tests/api/__tests__/database/index.js b/integration-tests/api/__tests__/database/index.js new file mode 100644 index 0000000000000..7a86d6f6b701f --- /dev/null +++ b/integration-tests/api/__tests__/database/index.js @@ -0,0 +1,56 @@ +const path = require("path") + +const setupServer = require("../../../helpers/setup-server") +const { initDb, useDb } = require("../../../helpers/use-db") + +jest.setTimeout(30000) + +describe("Database options", () => { + let medusaProcess + let dbConnection + + beforeAll(async () => { + const cwd = path.resolve(path.join(__dirname, "..", "..")) + dbConnection = await initDb({ + cwd, + database_extra: { idle_in_transaction_session_timeout: 1000 }, + }) + medusaProcess = await setupServer({ cwd }) + }) + + afterAll(async () => { + const db = useDb() + await db.shutdown() + medusaProcess.kill() + }) + + describe("idle_in_transaction_session_timeout", () => { + it("Resolves successfully", async () => { + expect.assertions(1) + + let queryRunner + + try { + queryRunner = dbConnection.createQueryRunner() + await queryRunner.connect() + + await queryRunner.startTransaction() + + await queryRunner.query(`select * from product`) + + // Idle time is 1000 ms so this should timeout + await new Promise((resolve) => + setTimeout(() => resolve(console.log("")), 2000) + ) + + // This query should fail with a QueryRunnerAlreadyReleasedError + await queryRunner.commitTransaction() + } catch (error) { + // Query runner will be released in case idle_in_transaction_session_timeout kicks in + expect(error?.type || error.name).toEqual( + "QueryRunnerAlreadyReleasedError" + ) + } + }) + }) +}) diff --git a/integration-tests/helpers/use-db.js b/integration-tests/helpers/use-db.js index 87a20cb2286ec..b8f685f9983c8 100644 --- a/integration-tests/helpers/use-db.js +++ b/integration-tests/helpers/use-db.js @@ -78,7 +78,7 @@ const DbTestUtil = { const instance = DbTestUtil module.exports = { - initDb: async function ({ cwd }) { + initDb: async function ({ cwd, database_extra }) { const configPath = path.resolve(path.join(cwd, `medusa-config.js`)) const { projectConfig, featureFlags } = require(configPath) @@ -98,6 +98,7 @@ module.exports = { database: projectConfig.database_database, synchronize: true, entities, + extra: database_extra ?? {}, }) instance.setDb(dbConnection) @@ -137,6 +138,7 @@ module.exports = { url: DB_URL, entities: enabledEntities, migrations: enabledMigrations, + extra: database_extra ?? {}, name: "integration-tests", }) diff --git a/packages/medusa/src/index.js b/packages/medusa/src/index.js index 1848d319eec9a..57a6103537b66 100644 --- a/packages/medusa/src/index.js +++ b/packages/medusa/src/index.js @@ -1,14 +1,11 @@ export * from "./api" export * from "./interfaces" -export * from "./types/inventory" -export * from "./types/stock-location" -export * from "./types/common" -export * from "./types/price-list" -export * from "./types/batch-job" -export * from "./types/global" export * from "./models" export * from "./services" -export * from "./utils" +export * from "./types/batch-job" +export * from "./types/common" export * from "./types/global" +export * from "./types/inventory" +export * from "./types/price-list" export * from "./types/stock-location" -export * from "./types/common" +export * from "./utils"