Skip to content

Commit 6cd1900

Browse files
authored
Merge pull request #2196 from astandrik/fix/1696-soak-runtime-isolation
fix(test): isolate soak harness daemon runtime
2 parents d1be392 + 81a8a03 commit 6cd1900

3 files changed

Lines changed: 105 additions & 7 deletions

File tree

‎scripts/soak-test.sh‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,17 @@ CBM_SOAK_MODE="${CBM_SOAK_MODE:-default}"
6666
RESULTS_DIR="${RESULTS_DIR:-soak-results}"
6767
mkdir -p "$RESULTS_DIR"
6868

69-
# Isolate daemon coordination from interactive CBM sessions and give this run
70-
# a deterministic host-side daemon log. Wine needs a Windows-form cache path
71-
# in the child environment while this Bash harness retains the host path.
69+
# Every product process below must reach a daemon rendezvous this run owns.
70+
# Only CBM_RUNTIME_DIR moves that rendezvous — a private CBM_CACHE_DIR alone
71+
# still shares the operator's account daemon (#1691, #1696).
72+
# shellcheck source=test-runtime.sh
73+
source "$(dirname "${BASH_SOURCE[0]}")/test-runtime.sh"
74+
cbm_test_runtime_init
75+
trap 'cbm_test_runtime_cleanup "$BINARY"' EXIT
76+
77+
# Give this run a deterministic host-side daemon log. Wine needs a Windows-form
78+
# cache path in the child environment while this Bash harness retains the host
79+
# path.
7280
#
7381
# On native Windows the cache CANNOT live under msys /tmp: the server's
7482
# cache-private executable-identity check walks the cache path's ancestors
@@ -146,7 +154,7 @@ if [[ "$BINARY" == *.exe ]] && command -v cygpath >/dev/null 2>&1 &&
146154
exit 1
147155
fi
148156
else
149-
SOAK_CACHE_DIR_HOST=$(mktemp -d "${TMPDIR:-/tmp}/cbm-soak-cache.XXXXXX")
157+
SOAK_CACHE_DIR_HOST="$CBM_TEST_CACHE_DIR_HOST"
150158
fi
151159
SOAK_CACHE_DIR_VALUE="$SOAK_CACHE_DIR_HOST"
152160
if [[ "$BINARY" == *.exe ]] && command -v winepath >/dev/null 2>&1; then
@@ -206,7 +214,12 @@ soak_cleanup() {
206214
if [ -f "$DAEMON_LOG" ]; then
207215
cp "$DAEMON_LOG" "$RESULTS_DIR/cbm-daemon.log" 2>/dev/null || true
208216
fi
209-
rm -rf -- "$SOAK_PROJECT" "$SOAK_CACHE_DIR_HOST"
217+
rm -rf -- "$SOAK_PROJECT"
218+
# The helper stops this run's private daemon before removing its root and
219+
# leaves the root behind for diagnosis when the daemon will not stop. The
220+
# native-Windows cache sits under SOAK_WIN_ROOT, which goes only after the
221+
# daemon check because the binary it probes with is the copy inside it.
222+
cbm_test_runtime_cleanup "$BINARY"
210223
[ -z "${SOAK_WIN_ROOT:-}" ] || rm -rf -- "$SOAK_WIN_ROOT"
211224
}
212225

@@ -807,7 +820,7 @@ if [ "$SKIP_CRASH" != "--skip-crash-test" ] && [ "$CBM_SOAK_MODE" != "query-leak
807820
SERVER_PID=""
808821
exec 3>&- 4<&-
809822
if ! wait_for_daemon_stop "$DAEMON_STOP_COUNT"; then
810-
echo "FAIL: last-session crash did not stop the shared daemon"
823+
echo "FAIL: last-session crash did not stop the private daemon"
811824
exit 1
812825
fi
813826

@@ -848,7 +861,7 @@ kill "$SERVER_PID" 2>/dev/null || true
848861
wait "$SERVER_PID" 2>/dev/null || true
849862
SERVER_PID=""
850863
if ! wait_for_daemon_stop "$FINAL_DAEMON_STOP_COUNT"; then
851-
echo "FAIL: final frontend shutdown did not stop the shared daemon"
864+
echo "FAIL: final frontend shutdown did not stop the private daemon"
852865
PASS=false
853866
fi
854867

‎scripts/test.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ bash "$ROOT/tests/test_ui_dev_proxy_security.sh"
212212
echo "=== Step 0d: daemon soak recovery contract ==="
213213
bash "$ROOT/tests/test_soak_daemon_recovery_contract.sh"
214214

215+
echo "=== Step 0d2: soak harness runtime isolation contract (#1696) ==="
216+
bash "$ROOT/tests/test_soak_runtime_isolation_contract.sh"
217+
215218
echo "=== Step 0e: Windows launcher bundle contract ==="
216219
bash "$ROOT/tests/test_windows_bundle_contract.sh"
217220

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Runtime-isolation contract for the soak harness (#1696, follow-up to #1691).
5+
#
6+
# scripts/soak-test.sh must be the only client of the daemon it measures: it
7+
# asserts that a session crash and the final shutdown each stop "the daemon".
8+
# It used to claim isolation from interactive sessions through a private
9+
# CBM_CACHE_DIR, but only CBM_RUNTIME_DIR moves the daemon rendezvous
10+
# (docs/CONFIGURATION.md), so the soak shared the operator's account daemon
11+
# and either stopped it or was refused with a cache-root conflict. Drive the
12+
# harness with an environment-probe fixture and require that no product
13+
# process ever receives the caller's runtime or cache.
14+
15+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
16+
WORKDIR="$(mktemp -d)"
17+
trap 'rm -rf "$WORKDIR"' EXIT
18+
19+
fail() {
20+
echo "FAIL: $*" >&2
21+
exit 1
22+
}
23+
24+
normalize_path() {
25+
local path=${1%$'\r'}
26+
if command -v cygpath >/dev/null 2>&1; then
27+
cygpath -u "$path" 2>/dev/null && return 0
28+
fi
29+
printf '%s\n' "${path//\\//}"
30+
}
31+
32+
ENV_PROBE="$WORKDIR/environment-probe"
33+
cat > "$ENV_PROBE" <<'EOF'
34+
#!/usr/bin/env bash
35+
printf '%s\t%s\n' "${CBM_CACHE_DIR-}" "${CBM_RUNTIME_DIR-}" >> "$CBM_SOAK_ENV_PROBE"
36+
[[ "${1-} ${2-}" == "daemon status" ]] && exit 1
37+
exit 0
38+
EOF
39+
chmod +x "$ENV_PROBE"
40+
41+
CALLER_CACHE="$WORKDIR/caller-cache"
42+
CALLER_RUNTIME="$WORKDIR/caller-runtime"
43+
ENV_LOG="$WORKDIR/environment.log"
44+
mkdir -p "$CALLER_CACHE" "$CALLER_RUNTIME"
45+
46+
# The fixture exits as soon as it has recorded its environment, so the soak
47+
# fails at "server did not start"; only the environment it handed to the
48+
# product is under test here. RESULTS_DIR keeps the soak's metrics out of cwd.
49+
CBM_CACHE_DIR="$CALLER_CACHE" \
50+
CBM_RUNTIME_DIR="$CALLER_RUNTIME" \
51+
CBM_SOAK_ENV_PROBE="$ENV_LOG" \
52+
RESULTS_DIR="$WORKDIR/results" \
53+
"$ROOT/scripts/soak-test.sh" "$ENV_PROBE" 1 --skip-crash-test \
54+
> "$WORKDIR/soak.out" 2>&1 || true
55+
56+
[[ -s "$ENV_LOG" ]] || fail "soak-test did not execute the environment-probe fixture"
57+
58+
CALLER_CACHE_NORMALIZED=$(normalize_path "$CALLER_CACHE")
59+
CALLER_RUNTIME_NORMALIZED=$(normalize_path "$CALLER_RUNTIME")
60+
private_root=""
61+
while IFS=$'\t' read -r child_cache_raw child_runtime_raw; do
62+
child_cache=$(normalize_path "$child_cache_raw")
63+
child_runtime=$(normalize_path "$child_runtime_raw")
64+
if [[ -z "$child_runtime" || "$child_runtime" == "$CALLER_RUNTIME_NORMALIZED" ]]; then
65+
fail "soak-test exposed the caller CBM_RUNTIME_DIR to a product process"
66+
fi
67+
if [[ -z "$child_cache" || "$child_cache" == "$CALLER_CACHE_NORMALIZED" ]]; then
68+
fail "soak-test exposed the caller CBM_CACHE_DIR to a product process"
69+
fi
70+
if [[ "${child_runtime%/*}" != "${child_cache%/*}" ||
71+
"${child_runtime##*/}" != "runtime" || "${child_cache##*/}" != "cache" ]]; then
72+
fail "soak runtime/cache were not isolated beneath one private root"
73+
fi
74+
if [[ -n "$private_root" && "$private_root" != "${child_runtime%/*}" ]]; then
75+
fail "soak-test switched private roots mid-run"
76+
fi
77+
private_root="${child_runtime%/*}"
78+
done < "$ENV_LOG"
79+
80+
[[ ! -e "$private_root" ]] || fail "soak-test left its private root behind: $private_root"
81+
82+
echo "PASS: soak harness isolates its daemon runtime and cache from the caller"

0 commit comments

Comments
 (0)