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

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

Merged
merged 8 commits into from
Jan 6, 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
5 changes: 5 additions & 0 deletions .changeset/wet-snakes-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

tests(integration-tests): Add integration test suite for database options
56 changes: 56 additions & 0 deletions integration-tests/api/__tests__/database/index.js
Original file line number Diff line number Diff line change
@@ -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"
)
}
})
})
})
4 changes: 3 additions & 1 deletion integration-tests/helpers/use-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -98,6 +98,7 @@ module.exports = {
database: projectConfig.database_database,
synchronize: true,
entities,
extra: database_extra ?? {},
})

instance.setDb(dbConnection)
Expand Down Expand Up @@ -137,6 +138,7 @@ module.exports = {
url: DB_URL,
entities: enabledEntities,
migrations: enabledMigrations,
extra: database_extra ?? {},
name: "integration-tests",
})

Expand Down
13 changes: 5 additions & 8 deletions packages/medusa/src/index.js
Original file line number Diff line number Diff line change
@@ -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"