Skip to content

Commit 1be9a28

Browse files
committed
Improve test script reliability and performance
1 parent f3ded3c commit 1be9a28

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

scripts/run-android-tests.sh

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,33 +160,55 @@ run_tests() {
160160

161161
# Start logcat, streaming to stdout and monitoring for completion
162162
highlight "Reading logs..."
163-
164163
local exit_code=1 # Default general failure
165164
local clean_exit=0
165+
local logcat_cmd="timeout $TEST_TIMEOUT adb logcat --pid=$pid -s $LOGCAT_FILTERS"
166+
167+
# Function to monitor Android app process and kill logcat if it dies
168+
monitor_app() {
169+
while true; do
170+
local app_pid=$(adb shell pidof io.sentry.godot.project 2>/dev/null || echo "")
171+
if [ -z "$app_pid" ]; then
172+
# App died, kill logcat
173+
pkill --full "$logcat_cmd" 2>/dev/null || true
174+
break
175+
fi
176+
sleep 1
177+
done
178+
}
179+
180+
# Start monitoring in background
181+
monitor_app &
182+
local monitor_pid=$!
166183

167184
# Process logcat output
168185
while IFS= read -r line; do
169186
echo "$line"
170187

171-
# Check for test run completion
172-
if echo "$line" | grep -q ">>> Test run complete with code:"; then
173-
exit_code=$(echo "$line" | sed 's/.*>>> Test run complete with code: \([0-9]*\).*/\1/')
174-
# Not quitting yet -- waiting for Godot to terminate.
175-
fi
176-
177-
# Check Godot exit condition
178-
if echo "$line" | grep -q "OnGodotTerminating"; then
179-
clean_exit=1
180-
timeout 2 cat || true # Continue reading for a bit in case there are remaining logs
181-
break
182-
fi
183-
done < <(timeout $TEST_TIMEOUT adb logcat --pid=$pid -s $LOGCAT_FILTERS)
188+
case "$line" in
189+
# Check for test run completion
190+
*">>> Test run complete with code:"*)
191+
exit_code=$(echo "$line" | sed 's/.*>>> Test run complete with code: \([0-9]*\).*/\1/')
192+
# Not quitting yet -- waiting for Godot to terminate.
193+
;;
194+
# Check Godot exit condition
195+
*"OnGodotTerminating"*)
196+
clean_exit=1
197+
timeout 2 cat || true # Continue reading for a bit in case there are remaining logs
198+
break
199+
;;
200+
esac
201+
done < <($logcat_cmd)
184202

185203
# Check if never finished
186204
if [ $exit_code -eq 1 ]; then
187205
error "Test run was interrupted or failed to complete properly!"
188206
fi
189207

208+
# Kill app monitor
209+
kill $monitor_pid 2>/dev/null || true
210+
wait $monitor_pid 2>/dev/null || true
211+
190212
# Check if process still running
191213
local current_pid=$(adb shell pidof io.sentry.godot.project 2>/dev/null || echo "")
192214
if [ -n "$current_pid" ]; then
@@ -195,6 +217,10 @@ run_tests() {
195217
fi
196218
error "Godot app process still running"
197219
adb shell am force-stop io.sentry.godot.project
220+
# Wait for process to quit
221+
while adb shell kill -0 "$current_pid"; do
222+
sleep 1
223+
done
198224
# Check if not exited cleanly
199225
elif [ $clean_exit -eq 0 ]; then
200226
warning "Unclean exit detected. Godot possibly crashed."

0 commit comments

Comments
 (0)