Skip to content

Commit 3fbd661

Browse files
authored
Merge PR #17: document selfhost health retry counts
Clarify the selfhost health retry count test and keep the shell helper readable.
2 parents 68d7a29 + f2cc55a commit 3fbd661

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

local/scripts/selfhost-shell.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { spawnSync } from "node:child_process";
33
import { describe, expect, it } from "vitest";
44

55
const publicRoot = path.resolve(__dirname, "../..");
6+
const BASH_NON_INTERACTIVE_COMMAND =
7+
"if command -v setsid >/dev/null 2>&1; then exec setsid \"$BASH\" -s; fi; exec \"$BASH\" -s";
68

79
function runBash(script: string) {
8-
return spawnSync("bash", ["-lc", "if command -v setsid >/dev/null 2>&1; then exec setsid \"$BASH\" -s; fi; exec \"$BASH\" -s"], {
10+
return spawnSync("bash", ["-lc", BASH_NON_INTERACTIVE_COMMAND], {
911
cwd: publicRoot,
1012
encoding: "utf8",
1113
input: script,
@@ -194,14 +196,15 @@ ENV
194196
return 0
195197
}
196198
curl_count_file="$home/curl-count"
199+
ready_threshold=5
197200
printf '0\\n' > "$curl_count_file"
198201
curl() {
199202
count="$(cat "$curl_count_file")"
200203
count=$((count + 1))
201204
printf '%s\\n' "$count" > "$curl_count_file"
202205
case "$*" in
203206
*"/api/health/live"*) return 0 ;;
204-
*"/api/health/ready"*) [ "$count" -ge 5 ]; return $? ;;
207+
*"/api/health/ready"*) [ "$count" -ge "$ready_threshold" ]; return $? ;;
205208
esac
206209
return 1
207210
}
@@ -214,6 +217,7 @@ ENV
214217
expect(result.status).toBe(0);
215218
expect(result.stdout).toContain("健康检查: 正常");
216219
expect(result.stdout).not.toContain("健康检查: 异常");
220+
// wait_for_health stops once ready succeeds, then status_cmd performs one final live+ready check.
217221
expect(result.stdout).toContain("curl_count=7");
218222
});
219223

0 commit comments

Comments
 (0)