From 180d831e8c3721aa22dd9ec25dbd6d67b0c30e7e Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 23 Dec 2024 17:48:18 +0000 Subject: [PATCH] Playwright: wait for the network listener on the postgres db As commented. This was flaking when I was debugging it locally (MAS was failing to start because the database wasn't ready). --- playwright/plugins/postgres/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/playwright/plugins/postgres/index.ts b/playwright/plugins/postgres/index.ts index bb63016c7a1..23d37ffef67 100644 --- a/playwright/plugins/postgres/index.ts +++ b/playwright/plugins/postgres/index.ts @@ -21,13 +21,15 @@ export class PostgresDocker extends Docker { super(); } - private async waitForPostgresReady(): Promise { + private async waitForPostgresReady(ipAddress: string): Promise { 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 }; }