Skip to content

Commit

Permalink
initial working version
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Feb 21, 2024
1 parent be7f20b commit 7648494
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ export const getTestPostgresDatabaseFactory = <
>(
options?: GetTestPostgresDatabaseFactoryOptions<Params>
) => {
console.log("options", options)
const initialData: InitialWorkerData = {
postgresVersion: options?.postgresVersion ?? "14",
containerOptions: options?.container,
pgbouncerOptions: options?.pgbouncer,
}

const workerPromise = getWorker(initialData, options as any)
Expand Down
1 change: 1 addition & 0 deletions src/worker-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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
27 changes: 16 additions & 11 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,27 @@ export class Worker {
)
}

const connectionString = `postgresql://postgres:@${startedContainer.getHost()}:${startedContainer.getMappedPort(
5432
)}/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({
PGBOUNCER_LISTEN_PORT: "6432",
PGBOUNCER_POOL_MODE: "transaction",
PGBOUNCER_MAX_CLIENT_CONN: "1000",
PGBOUNCER_DEFAULT_POOL_SIZE: "1000",
PGBOUNCER_SERVER_IDLE_TIMEOUT: "240",
PGBOUNCER_SERVER_CONNECT_TIMEOUT: "15",
PGBOUNCER_QUERY_TIMEOUT: "240",
PGBOUNCER_QUERY_WAIT_TIMEOUT: "240",
DATABASE_URL: connectionString,
// PGBOUNCER_LISTEN_PORT: "6432",
POOL_MODE: "transaction",
LISTEN_PORT: "6432",
// PGBOUNCER_MAX_CLIENT_CONN: "1000",
// PGBOUNCER_DEFAULT_POOL_SIZE: "1000",
// PGBOUNCER_SERVER_IDLE_TIMEOUT: "240",
// PGBOUNCER_SERVER_CONNECT_TIMEOUT: "15",
// PGBOUNCER_QUERY_TIMEOUT: "240",
// PGBOUNCER_QUERY_WAIT_TIMEOUT: "240",
})
.withStartupTimeout(120_000)
.withNetwork(network)
Expand All @@ -342,9 +349,7 @@ export class Worker {
pgbouncerContainer: startedPgbouncerContainer,
network,
postgresClient: new pg.Pool({
connectionString: `postgresql://postgres:@${startedContainer.getHost()}:${startedContainer.getMappedPort(
5432
)}/postgres`,
connectionString,
}),
}
}
Expand Down

0 comments on commit 7648494

Please sign in to comment.