Skip to content

Commit 3d2dbec

Browse files
committed
fix(ci): close Testbox SSH sessions on teardown
1 parent bd997c6 commit 3d2dbec

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎.github/workflows/ci-check-testbox.yml‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,24 @@ jobs:
185185

186186
- name: Run Testbox
187187
uses: useblacksmith/run-testbox@3f60ff9ceb2c10c3feefa87dc0c6490cffae059d
188-
if: github.event_name == 'workflow_dispatch' && always()
188+
if: github.event_name == 'workflow_dispatch' && !cancelled()
189189
env:
190190
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
191+
192+
- name: Close Testbox SSH sessions
193+
if: github.event_name == 'workflow_dispatch' && always()
194+
shell: bash
195+
run: |
196+
set -euo pipefail
197+
198+
runner_ssh_port="$(cat /tmp/.testbox/runner_ssh_port 2>/dev/null || true)"
199+
if [[ ! "$runner_ssh_port" =~ ^[0-9]+$ ]] ||
200+
(( runner_ssh_port < 1 || runner_ssh_port > 65535 )); then
201+
echo "No valid Testbox SSH port found; skipping session cleanup"
202+
exit 0
203+
fi
204+
205+
# run-testbox has no post hook. Close only Testbox client sockets so
206+
# Blacksmith's runner teardown does not wait for its 290-second grace.
207+
timeout --signal=KILL 5s sudo ss -K state established \
208+
"( sport = :${runner_ssh_port} )" || true

‎test/scripts/package-acceptance-workflow.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,7 @@ describe("package artifact reuse", () => {
23852385
const checkTestboxJob = workflowJob(CI_CHECK_TESTBOX_WORKFLOW, "check");
23862386
const setupNodeStep = workflowStep(checkTestboxJob, "Setup Node environment");
23872387
const runTestboxStep = workflowStep(checkTestboxJob, "Run Testbox");
2388+
const closeTestboxSshStep = workflowStep(checkTestboxJob, "Close Testbox SSH sessions");
23882389
const runArmTestboxStep = workflowStep(
23892390
workflowJob(CI_CHECK_ARM_TESTBOX_WORKFLOW, "check-arm"),
23902391
"Run Testbox",
@@ -2411,7 +2412,14 @@ describe("package artifact reuse", () => {
24112412
"${{ fromJSON(inputs.timeout_minutes || '120') }}",
24122413
);
24132414
expect(runTestboxStep.uses).toContain("useblacksmith/run-testbox@");
2414-
expect(runTestboxStep.if).toBe("github.event_name == 'workflow_dispatch' && always()");
2415+
expect(runTestboxStep.if).toBe("github.event_name == 'workflow_dispatch' && !cancelled()");
2416+
expect(closeTestboxSshStep.if).toBe("github.event_name == 'workflow_dispatch' && always()");
2417+
expect(closeTestboxSshStep.run).toContain(
2418+
'ss -K state established \\\n "( sport = :${runner_ssh_port} )"',
2419+
);
2420+
expect(checkTestboxJob.steps.indexOf(closeTestboxSshStep)).toBe(
2421+
checkTestboxJob.steps.indexOf(runTestboxStep) + 1,
2422+
);
24152423
expect(runArmTestboxStep.if).toBe("always()");
24162424
expect(runBuildArtifactsTestboxStep.if).toBe("always()");
24172425
expect(runWindowsTestboxStep.if).toBe("always()");

0 commit comments

Comments
 (0)