Skip to content

Commit

Permalink
fix: enhance postgres health check
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Nov 10, 2024
1 parent e165a4d commit e367768
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 10 deletions.
251 changes: 242 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
"@playwright/test": "^1.48.2",
"@types/ms": "^0.7.34",
"@types/node": "^22.8.5",
"@types/pg": "^8.11.10",
"@types/ws": "^8.5.12",
"esbuild": "^0.24.0",
"pg": "^8.13.1",
"typescript": "^5.6.3"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Postgres {
imageName: 'postgres:latest',
ports: [POSTGRES_PORT],
healthcheck: {
test: ['CMD-SHELL', 'pg_isready'],
test: ['CMD-SHELL', 'pg_isready', `--username=${user}`, `--host=localhost`, `--port=${POSTGRES_PORT}`, `--dbname=${db}`],
intervalMs: ms('1s'),
retries: 10,
startPeriodMs: 0,
Expand Down
16 changes: 16 additions & 0 deletions tests/postgres.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test } from '@playwright/test';
import pg from 'pg';
import { Postgres } from '../src/postgres.js';

test('should work', async ({}) => {
const s = await Postgres.start({
user: 'foo',
password: 'bar',
db: 'postgres',
});
const client = new pg.Client(s.connectOptions());
await client.connect();
await client.query('SELECT 1');
await client.end();
await s.stop();
})

0 comments on commit e367768

Please sign in to comment.