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

Playwright: wait for the network listener on the postgres db #28808

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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
8 changes: 5 additions & 3 deletions playwright/plugins/postgres/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export class PostgresDocker extends Docker {
super();
}

private async waitForPostgresReady(): Promise<void> {
private async waitForPostgresReady(ipAddress: string): Promise<void> {
const waitTimeMillis = 30000;
const startTime = new Date().getTime();
let lastErr: Error | null = null;
while (new Date().getTime() - startTime < waitTimeMillis) {
try {
await this.exec(["pg_isready", "-U", "postgres"], true);
// Note that we specify the IP address rather than letting it connect to the local
// socket: that's the listener we care about and empirically it matters.
await this.exec(["pg_isready", "-h", ipAddress, "-U", "postgres"], true);
lastErr = null;
break;
} catch (err) {
Expand Down Expand Up @@ -57,7 +59,7 @@ export class PostgresDocker extends Docker {
const ipAddress = await this.getContainerIp();
console.log(new Date(), "postgres container up");

await this.waitForPostgresReady();
await this.waitForPostgresReady(ipAddress);
console.log(new Date(), "postgres container ready");
return { ipAddress, containerId };
}
Expand Down
Loading