Skip to content

Commit 60b3bc7

Browse files
committed
fix: [sc-106107] Make the wedged-stop assertion measure the stop it issues, and survive launchctl's exit code
The macOS job failed this step immediately after it had printed its own success message. The pwsh shell ends by exiting with $LASTEXITCODE, and `launchctl stop` returns non-zero in situations that are not failures here - the repo's own stop-service action already guards it with `|| true`. Windows and Linux passed only because sc.exe and systemctl happen to return zero. Report the stop command's exit code and clear it: whether the stop was honored is decided by the agent's log, not by the service manager's exit status. The step now exits explicitly on both paths rather than inheriting whatever was left behind. That failure also exposed a second, quieter bug: the assertion compared against the scenario-wide "Service stopped" baseline, but the --update that points the agent at the stub broker restarts the service and logs its own "Service stopped". The delta was therefore already satisfied before the stop under test was issued, which is why the step reported success after 0.2s - it was observing the update's restart, not the wedged stop, on every platform. Count the lines immediately before issuing the stop so the delta can only come from it.
1 parent d30cacd commit 60b3bc7

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,10 @@ jobs:
520520
$subscribed = Get-PatternCount $content "Subscribed to messages"
521521
$timedOut = Get-PatternCount $content "Failed to subscribe: timed out waiting for broker acknowledgement"
522522
$backoffs = Get-PatternCount $content "Reconnecting in"
523-
$stops = Get-PatternCount $content "Service stopped"
524523
"subscribed=$subscribed" >> $env:GITHUB_OUTPUT
525524
"timed_out=$timedOut" >> $env:GITHUB_OUTPUT
526525
"backoffs=$backoffs" >> $env:GITHUB_OUTPUT
527-
"stops=$stops" >> $env:GITHUB_OUTPUT
528-
Write-Output "Baseline -> subscribed=$subscribed timed_out=$timedOut backoffs=$backoffs stops=$stops"
526+
Write-Output "Baseline -> subscribed=$subscribed timed_out=$timedOut backoffs=$backoffs"
529527
530528
# Read off a logged path rather than re-deriving the platform path; see the
531529
# fuller note on the bounded-output scenario's copy of this step.
@@ -670,9 +668,21 @@ jobs:
670668
env:
671669
LOG_FILE: ${{ matrix.log_file }}
672670
SERVICE: ${{ matrix.service }}
673-
BASE_STOPS: ${{ steps.suback_baseline.outputs.stops }}
674671
run: |
675-
$baseStops = [int]$env:BASE_STOPS
672+
function Get-StopCount {
673+
$content = Get-Content $env:LOG_FILE -Raw -ErrorAction SilentlyContinue
674+
if ($content) { ([regex]::Matches($content, [regex]::Escape("Service stopped"))).Count } else { 0 }
675+
}
676+
677+
# Counted here rather than reusing the scenario-wide baseline: the
678+
# --update that pointed the agent at the stub broker restarts the
679+
# service, and that restart logs its own "Service stopped". Measured
680+
# against the older baseline the delta was already satisfied before this
681+
# stop was even issued, so the assertion "passed" in 0.2s without
682+
# observing the stop it exists to test.
683+
$before = Get-StopCount
684+
Write-Output "Service stopped lines before issuing the stop: $before"
685+
676686
$sw = [System.Diagnostics.Stopwatch]::StartNew()
677687
678688
if ($IsWindows) {
@@ -683,14 +693,21 @@ jobs:
683693
sudo launchctl stop "system/$($env:SERVICE)"
684694
}
685695
696+
# launchctl exits non-zero in situations that are not failures here -
697+
# the repo's own stop-service action already guards it with `|| true` -
698+
# and the pwsh shell ends by exiting with $LASTEXITCODE, which failed
699+
# this step on macOS even after the assertion below had passed. Report
700+
# the code and clear it; whether the stop was honored is decided by the
701+
# agent's log, not by the service manager's exit status.
702+
Write-Output "Stop command exit code: $LASTEXITCODE"
703+
$global:LASTEXITCODE = 0
704+
686705
# A clean exit runs the agent's deferred teardown, whose last act is the
687706
# "Service stopped" line; a force-kill past the stop deadline never
688707
# produces one.
689708
$stopped = $false
690709
while ($sw.Elapsed.TotalSeconds -lt 30) {
691-
$content = Get-Content $env:LOG_FILE -Raw -ErrorAction SilentlyContinue
692-
$stops = if ($content) { ([regex]::Matches($content, [regex]::Escape("Service stopped"))).Count } else { 0 }
693-
if ($stops -gt $baseStops) { $stopped = $true; break }
710+
if ((Get-StopCount) -gt $before) { $stopped = $true; break }
694711
Start-Sleep -Milliseconds 500
695712
}
696713
$sw.Stop()
@@ -700,6 +717,7 @@ jobs:
700717
exit 1
701718
}
702719
Write-Output "Service stopped cleanly after $([math]::Round($sw.Elapsed.TotalSeconds, 1))s while wedged"
720+
exit 0
703721
704722
- name: Assert no orphaned scripts after the wedged stop
705723
uses: ./.github/actions/assert-no-orphaned-scripts

0 commit comments

Comments
 (0)