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

As commented. This was flaking when I was debugging it locally
(MAS was failing to start because the database wasn't ready).
pull/28652/merge
David Baker 2024-12-23 18:06:37 +00:00 committed by GitHub
parent 0b24d33c64
commit 7e1927d388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -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) {
@ -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 };
}