Skip to content

Commit 1eacd00

Browse files
committed
Added waiting instead of sleep
1 parent c20ba52 commit 1eacd00

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@ jobs:
4343
echo "port = 5432" >> "$PGDATA/postgresql.conf"
4444
$PG_BIN = "C:\Program Files\PostgreSQL\14\bin"
4545
$env:PATH = "$PG_BIN;$env:PATH"
46-
Write-Host "PATH=$env:PATH"
4746
4847
# start and wait
4948
pg_ctl start
50-
Start-Sleep -Seconds 15
49+
$timeout = 120
50+
$elapsedTime = 0
51+
Write-Host "Waiting for PostgreSQL to start"
52+
while ($elapsedTime -lt $timeout) {
53+
$pgIsReadyResult = & $PG_BIN\pg_isready.exe -h localhost -p 5432 -t 1
54+
if ($pgIsReadyResult -eq "localhost:5432 - accepting connections") {
55+
Write-Host "PostgreSQL is ready"
56+
break
57+
}
58+
Start-Sleep -Seconds 5
59+
$elapsedTime += 5
60+
}
5161
5262
# setup db
5363
cd database
@@ -72,6 +82,25 @@ jobs:
7282
sc.exe create Redis binpath=C:\redis\RedisService.exe start= auto
7383
net start Redis
7484
85+
# wait for redis
86+
Write-Host "Waiting for Redis to start"
87+
while ($elapsedTime -lt $timeout) {
88+
$redisPingResult = & C:\redis\redis-cli.exe ping
89+
if ($redisPingResult -eq "PONG") {
90+
Write-Host "Redis is ready"
91+
break
92+
}
93+
Start-Sleep -Seconds 5
94+
$elapsedTime += 5
95+
}
96+
97+
if ($elapsedTime -ge $timeout) {
98+
Write-Host "Timeout waiting for services to start."
99+
exit 1
100+
}
101+
102+
Write-Host "Services are ready"
103+
75104
- name: Setup (on Linux)
76105
if: runner.os == 'Linux'
77106
run: |

0 commit comments

Comments
 (0)