Why: C4 and C5 need a shared way to start, refuse, and tear down stacks without touching production ports or processes. Evidence: tests/ops/self_check.sh passed (help, unknown arg, foreign name, production port, busy port, SIGINT cleanup). drill_driver go test passed. Impact: New tests/ops library and HTTP driver. No drill result and no release-gate change yet. Refs: docs/release-multi-instance.md C4 C5 Co-authored-by: Cursor <cursoragent@cursor.com>
106 lines
2.3 KiB
Bash
Executable File
106 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# lib.sh 的正常 / 拒绝 / 中断回收自检。不测量吞吐,不受 load 门槛约束。
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
# shellcheck source=lib.sh
|
|
source "$ROOT/tests/ops/lib.sh"
|
|
|
|
usage() {
|
|
echo "tests/ops/self_check.sh [--hold]"
|
|
}
|
|
|
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
|
usage
|
|
exit 0
|
|
fi
|
|
|
|
if [[ "${1:-}" == "--hold" ]]; then
|
|
owned=0
|
|
cleanup() {
|
|
trap - EXIT INT TERM
|
|
if [[ "$owned" -eq 1 ]]; then
|
|
ops_pg_remove "$ROOT" u7drill || true
|
|
fi
|
|
exit 0
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
ops_pg_create "$ROOT" u7drill 18989
|
|
owned=1
|
|
ops_pg_start "$ROOT" u7drill
|
|
: >"$ROOT/runtime/u7drill/hold.ready"
|
|
sleep 3600
|
|
exit 0
|
|
fi
|
|
|
|
if [[ $# -gt 0 ]]; then
|
|
echo "[ops] unknown arg: $1" >&2
|
|
exit 2
|
|
fi
|
|
|
|
echo "[ops] self-check: --help"
|
|
"$0" --help >/dev/null
|
|
|
|
echo "[ops] self-check: unknown arg exits 2"
|
|
set +e
|
|
"$0" --nope >/dev/null 2>&1
|
|
ec=$?
|
|
set -e
|
|
[[ "$ec" -eq 2 ]]
|
|
|
|
echo "[ops] self-check: foreign name and production port are refused"
|
|
set +e
|
|
ops_require_name prod
|
|
ec=$?
|
|
set -e
|
|
[[ "$ec" -eq 2 ]]
|
|
set +e
|
|
ops_require_port 8787
|
|
ec=$?
|
|
set -e
|
|
[[ "$ec" -eq 2 ]]
|
|
|
|
echo "[ops] self-check: busy port is refused before create"
|
|
python3 -m http.server 18988 --bind 127.0.0.1 >/dev/null 2>&1 &
|
|
busy_pid=$!
|
|
for _ in $(seq 1 20); do ops_port_listening 18988 && break; sleep 0.1; done
|
|
set +e
|
|
ops_pg_create "$ROOT" u7drill 18988
|
|
ec=$?
|
|
set -e
|
|
kill "$busy_pid" 2>/dev/null || true
|
|
wait "$busy_pid" 2>/dev/null || true
|
|
[[ "$ec" -eq 2 ]]
|
|
[[ ! -e "$ROOT/runtime/u7drill" ]]
|
|
|
|
echo "[ops] self-check: SIGINT removes the instance and the port"
|
|
set -m
|
|
"$0" --hold >/tmp/u7ops-hold.txt 2>&1 &
|
|
hold_pid=$!
|
|
set +m
|
|
ready=0
|
|
for _ in $(seq 1 90); do
|
|
if [[ -f "$ROOT/runtime/u7drill/hold.ready" ]]; then
|
|
ready=1
|
|
break
|
|
fi
|
|
if ! kill -0 "$hold_pid" 2>/dev/null; then
|
|
break
|
|
fi
|
|
sleep 0.5
|
|
done
|
|
if [[ "$ready" -ne 1 ]]; then
|
|
cat /tmp/u7ops-hold.txt >&2 || true
|
|
echo "[ops] hold did not become ready" >&2
|
|
exit 1
|
|
fi
|
|
kill -INT -- "-$hold_pid" 2>/dev/null || kill -INT "$hold_pid" 2>/dev/null || true
|
|
set +e
|
|
wait "$hold_pid"
|
|
set -e
|
|
if ops_port_listening 18989 || [[ -e "$ROOT/runtime/u7drill" ]]; then
|
|
echo "[ops] SIGINT left port 18989 or runtime/u7drill behind" >&2
|
|
exit 1
|
|
fi
|
|
echo "[ops] self-check passed"
|