Skip to content

Commit 46cc212

Browse files
committed
fix(e2e): use host pg_isready/psql for DB readiness check
The previous implementation used `docker run --network host` which does not work on Docker Desktop for macOS/Windows. Now uses host pg_isready (if available) with psql fallback for cross-platform support.
1 parent f6a969e commit 46cc212

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

cli/src/__tests__/e2e/test-db-utils.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,32 @@ export async function createE2EDatabase(describeId: string): Promise<E2EDatabase
9191

9292
/**
9393
* Wait for database to be ready to accept connections
94+
* Uses pg_isready if available on the host, otherwise falls back to a simple psql connection check.
95+
* Note: We don't use `docker run --network host` because it doesn't work on Docker Desktop for macOS/Windows.
9496
*/
9597
async function waitForDatabase(port: number, timeoutMs: number = 30000): Promise<void> {
9698
const startTime = Date.now()
9799

98100
while (Date.now() - startTime < timeoutMs) {
99101
try {
102+
// Try pg_isready first (if installed on host)
100103
execSync(
101-
`docker run --rm --network host postgres:16 pg_isready -h localhost -p ${port} -U manicode_e2e_user -d manicode_db_e2e`,
104+
`pg_isready -h localhost -p ${port} -U manicode_e2e_user -d manicode_db_e2e`,
102105
{ stdio: 'pipe' }
103106
)
104107
return
105108
} catch {
106-
await sleep(500)
109+
// Fall back to psql connection check
110+
try {
111+
execSync(
112+
`PGPASSWORD=e2e_secret_password psql -h localhost -p ${port} -U manicode_e2e_user -d manicode_db_e2e -c 'SELECT 1'`,
113+
{ stdio: 'pipe' }
114+
)
115+
return
116+
} catch {
117+
// Database not ready yet
118+
await sleep(500)
119+
}
107120
}
108121
}
109122

0 commit comments

Comments
 (0)