fix(lab): avoid PostgreSQL pipeline deadlock [T-014]
Harness governance / validate (push) Has been cancelled
Harness governance / validate (push) Has been cancelled
This commit is contained in:
@@ -128,14 +128,23 @@ function Stop-ManagedProcess($Managed) {
|
|||||||
function Stop-AllManagedProcesses($Items) {
|
function Stop-AllManagedProcesses($Items) {
|
||||||
$processes = @($Items | Where-Object { $null -ne $_ -and $null -ne $_.Process })
|
$processes = @($Items | Where-Object { $null -ne $_ -and $null -ne $_.Process })
|
||||||
foreach ($item in $processes) {
|
foreach ($item in $processes) {
|
||||||
if (-not $item.Process.HasExited) {
|
try {
|
||||||
$item.Process.Kill()
|
if (-not $item.Process.HasExited) {
|
||||||
|
$item.Process.Kill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
if (-not $item.Process.HasExited) { throw }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($item in $processes) {
|
$cleanupWatch = [Diagnostics.Stopwatch]::StartNew()
|
||||||
if (-not $item.Process.HasExited) {
|
while ($cleanupWatch.Elapsed.TotalSeconds -lt 10 -and
|
||||||
$item.Process.WaitForExit(10000) | Out-Null
|
@($processes | Where-Object { -not $_.Process.HasExited }).Count -gt 0) {
|
||||||
}
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
$remaining = @($processes | Where-Object { -not $_.Process.HasExited })
|
||||||
|
if ($remaining.Count -gt 0) {
|
||||||
|
Write-Warning "managed processes did not exit within the shared cleanup deadline: $($remaining.Count)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,7 +616,12 @@ try {
|
|||||||
New-Item -ItemType Directory -Path $pgData | Out-Null
|
New-Item -ItemType Directory -Path $pgData | Out-Null
|
||||||
Invoke-Checked $script:initdb '-D' $pgData '-U' 'postgres' '-A' 'trust' '--encoding=UTF8' '--no-locale' '--no-sync'
|
Invoke-Checked $script:initdb '-D' $pgData '-U' 'postgres' '-A' 'trust' '--encoding=UTF8' '--no-locale' '--no-sync'
|
||||||
$serverOptions = "-h 127.0.0.1 -p $postgresPort -c listen_addresses=127.0.0.1"
|
$serverOptions = "-h 127.0.0.1 -p $postgresPort -c listen_addresses=127.0.0.1"
|
||||||
Invoke-Checked $script:pgCtl '-D' $pgData '-l' $pgLog '-o' $serverOptions '-w' 'start'
|
# Do not pipe pg_ctl start output: postgres can inherit the pipeline handle and
|
||||||
|
# keep PowerShell waiting until the server exits.
|
||||||
|
& $script:pgCtl '-D' $pgData '-l' $pgLog '-o' $serverOptions '-w' 'start'
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "required command failed with exit code $LASTEXITCODE"
|
||||||
|
}
|
||||||
$postgresStarted = $true
|
$postgresStarted = $true
|
||||||
Invoke-Checked $script:psql '-X' '-v' 'ON_ERROR_STOP=1' '-d' $adminRootDSN '-f' (Join-Path $script:repoRoot 'deploy\postgres\001_roles.sql')
|
Invoke-Checked $script:psql '-X' '-v' 'ON_ERROR_STOP=1' '-d' $adminRootDSN '-f' (Join-Path $script:repoRoot 'deploy\postgres\001_roles.sql')
|
||||||
Invoke-Checked $script:createdb '-h' '127.0.0.1' '-p' ([string]$postgresPort) '-U' 'postgres' $databaseName
|
Invoke-Checked $script:createdb '-h' '127.0.0.1' '-p' ([string]$postgresPort) '-U' 'postgres' $databaseName
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ class SenseCapacityContractTests(unittest.TestCase):
|
|||||||
self.assertIn("yovision-t014", self.script)
|
self.assertIn("yovision-t014", self.script)
|
||||||
self.assertIn("[IO.Path]::GetFileName($resolvedSession) -notlike 'session-*'", self.script)
|
self.assertIn("[IO.Path]::GetFileName($resolvedSession) -notlike 'session-*'", self.script)
|
||||||
self.assertIn("the existing PostgreSQL listener on port 5432 changed", self.script)
|
self.assertIn("the existing PostgreSQL listener on port 5432 changed", self.script)
|
||||||
|
self.assertNotRegex(self.script, r"Invoke-Checked \$script:pgCtl .* 'start'")
|
||||||
|
self.assertIn("$cleanupWatch.Elapsed.TotalSeconds -lt 10", self.script)
|
||||||
|
|
||||||
def test_runtime_secrets_and_sensitive_inventory_are_not_reported(self):
|
def test_runtime_secrets_and_sensitive_inventory_are_not_reported(self):
|
||||||
self.assertIn("New-SecretToken", self.script)
|
self.assertIn("New-SecretToken", self.script)
|
||||||
|
|||||||
Reference in New Issue
Block a user