diff --git a/actions/persistent-stores/action.yml b/actions/persistent-stores/action.yml index 1e022fd..bbd405c 100644 --- a/actions/persistent-stores/action.yml +++ b/actions/persistent-stores/action.yml @@ -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 }