Skip to content

Commit c6f09af

Browse files
committed
fix: Improve cleanup logic and enhance surfpool process management
1 parent 02cbdbc commit c6f09af

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

client/example/run-test.sh

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ main() {
9191
}
9292

9393
cleanup() {
94-
local surfpool_pid=$1
94+
local pid="${1:-}"
9595

96-
if [ -n "${surfpool_pid:-}" ]; then
97-
echo "Killing surfpool process with PID: $surfpool_pid"
98-
kill "$surfpool_pid" 2>/dev/null || true
96+
if [ -n "$pid" ]; then
97+
echo "Attempting to kill tracked surfpool process PID: $pid"
98+
kill "$pid" 2>/dev/null || true
9999
sleep 1
100-
kill -9 "$surfpool_pid" 2>/dev/null || true
100+
kill -9 "$pid" 2>/dev/null || true
101101
fi
102102

103-
# Kill remaining children
104-
pkill -P $$ || true
103+
echo "Ensuring all surfpool processes are stopped..."
104+
pkill -9 -f 'surfpool' 2>/dev/null || true
105+
106+
# Clean up any sub-processes from this script
107+
pkill -P $$ 2>/dev/null || true
105108
wait || true
106109
}
107110

@@ -129,24 +132,25 @@ check_surfpool() {
129132
}
130133

131134
start_surfpool() {
132-
surfpool start --ci --offline --daemon &
135+
surfpool start --ci --offline --daemon &>/dev/null &
133136
local surfpool_pid=$!
134137

135138
sleep 3
136139

140+
# Send setup output to stderr, not stdout
137141
surfpool run setup -u \
138142
--input composite_pid=$composite_pid \
139143
--input basic_2_pid=$basic_2_pid \
140144
--input basic_4_pid=$basic_4_pid \
141145
--input events_pid=$events_pid \
142-
--input optional_pid=$optional_pid
146+
--input optional_pid=$optional_pid \
147+
>&2
143148

144149
sleep 3
145150

146-
echo "Surfpool PID: $surfpool_pid"
147-
# check_surfpool $surfpool_pid
151+
echo "Surfpool PID: $surfpool_pid" >&2
148152

149-
echo $surfpool_pid
153+
echo "$surfpool_pid"
150154
}
151155

152156
declare -f -t trap_add

0 commit comments

Comments
 (0)