chore(integration-tests): Add test for database options (#2707)

**What**
- Add integration test suite for database options
- Expose integration tests DB to additional options
- Add test for `idle_in_transaction_session_timeout`
This commit is contained in:
Oliver Windall Juhl
2023-01-06 14:41:05 +01:00
committed by GitHub
parent 077e4d9606
commit 8ba0addea3
4 changed files with 70 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
tests(integration-tests): Add integration test suite for database options

View File

@@ -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"
)
}
})
})
})

View File

@@ -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",
})

View File

@@ -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/global"
export * from "./types/stock-location"
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 "./utils"