Skip to content
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
26 changes: 16 additions & 10 deletions actions/persistent-stores/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,24 @@ runs:

Start-Process consul -ArgumentList 'agent', '-dev', '-http-port=${{ inputs.consul_port }}'

# consul members exits non-zero until the agent's HTTP API responds.
# In dev mode the leader is self-elected immediately on startup, so
# this is purely a process-readiness check.
$deadline = (Get-Date).AddSeconds(30)
$ready = $false
while ((Get-Date) -lt $deadline) {
consul members -http-addr="http://127.0.0.1:${{ inputs.consul_port }}" 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) { $ready = $true; break }
# Start-Process returns immediately, so wait until the dev agent's HTTP
# API is up and serving (leader elected) before tests run.
$timeout = 30
$elapsed = 0
while ($elapsed -lt $timeout) {
try {
$response = Invoke-RestMethod -Uri 'http://127.0.0.1:${{ inputs.consul_port }}/v1/status/leader' -TimeoutSec 2
if ($response -and $response -ne '""') {
Write-Host "Consul is ready (leader: $response)"
break
}
} catch {}
Write-Host "Waiting for Consul to elect a leader... ($elapsed/$timeout seconds)"
Start-Sleep -Seconds 1
$elapsed++
}
if (-not $ready) {
Write-Error "Consul did not become ready within 30 seconds"
if ($elapsed -eq $timeout) {
Write-Error "Consul did not become ready within $timeout seconds"
exit 1
}

Expand Down