Skip to content

Commit

Permalink
initial test with poolMode testing
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Feb 21, 2024
1 parent 566cc39 commit a7db670
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const getTestPostgresDatabaseFactory = <
>(
options?: GetTestPostgresDatabaseFactoryOptions<Params>
) => {
console.log("options", options)
const initialData: InitialWorkerData = {
postgresVersion: options?.postgresVersion ?? "14",
containerOptions: options?.container,
Expand Down
14 changes: 13 additions & 1 deletion src/tests/pgbouncer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ test("pgbouncer", async (t) => {
pgbouncer: {
enabled: true,
version: "1.22.0",
poolMode: "statement",
},
})

const postgres13 = await getPostgres13(t)

t.truthy(postgres13.pgbouncerConnectionString)
await postgres13.pool.query("SELECT 1")
const result = await postgres13.pool.query("SELECT 1 as result")

t.is(result.rows[0].result, 1)

// can't use a transaction with statement pool mode
const err = await t.throwsAsync(postgres13.pool.query(`BEGIN TRANSACTION`))

t.truthy(
err!
.toString()
.includes("transaction blocks not allowed in statement pooling mode")
)
})
1 change: 0 additions & 1 deletion src/worker-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const workerWrapper = async (

const { initialData } = protocol

console.log("creating worker with initialData", initialData)
const worker = new Worker(initialData as any)

for await (const testWorker of protocol.testWorkers()) {
Expand Down
5 changes: 1 addition & 4 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,12 @@ export class Worker {
)}/postgres`

let startedPgbouncerContainer
console.log("pgbouncerOptions", this.initialData.pgbouncerOptions)
if (this.initialData.pgbouncerOptions?.enabled) {
const pgbouncerContainer = new GenericContainer("edoburu/pgbouncer")
.withExposedPorts(6432)
.withName(getRandomDatabaseName())
.withEnvironment({
DB_HOST: startedContainer.getHost(),
DB_HOST: startedContainer.getName().replace("/", ""),
DB_USER: "postgres",
DB_NAME: "*",
POOL_MODE:
Expand All @@ -336,9 +335,7 @@ export class Worker {
})
.withStartupTimeout(120_000)
.withNetwork(network)
console.log("attempting to start pg bouncer")
startedPgbouncerContainer = await pgbouncerContainer.start()
console.log("finishing starting pg bouncer")
}

return {
Expand Down

0 comments on commit a7db670

Please sign in to comment.