@@ -3,9 +3,11 @@ import { spawnSync } from "node:child_process";
33import { describe , expect , it } from "vitest" ;
44
55const 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
79function 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 }
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