Skip to content

Commit aeaec36

Browse files
committed
test: prove wake assertion through pmset
1 parent ea4b83c commit aeaec36

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

scripts/smoke-installed-app.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,21 @@ done
4444
exit 1
4545
}
4646

47-
hold_found=false
47+
hold_pid=""
4848
for attempt in {1..15}; do
49-
if ps -axo ppid=,command= | awk -v app_pid="${app_pid}" '$1 == app_pid && $2 == "/usr/bin/caffeinate" { found = 1 } END { exit !found }'; then
50-
hold_found=true
51-
break
52-
fi
49+
hold_pid="$(ps -axo pid=,ppid=,command= | awk -v app_pid="${app_pid}" '$2 == app_pid && $3 == "/usr/bin/caffeinate" { print $1 }')"
50+
[[ -n "${hold_pid}" ]] && break
5351
sleep 1
5452
done
55-
[[ "${hold_found}" == true ]] || {
53+
[[ -n "${hold_pid}" ]] || {
5654
echo "error: installed app did not create its owned wake hold" >&2
5755
exit 1
5856
}
57+
assertions="$(pmset -g assertions)"
58+
grep -q "pid ${hold_pid}(caffeinate)" <<<"${assertions}" || {
59+
echo "error: pmset did not report the owned wake assertion" >&2
60+
exit 1
61+
}
5962

6063
osascript -e 'tell application id "dev.uinaf.slopwake" to quit'
6164
for attempt in {1..10}; do
@@ -66,9 +69,14 @@ if kill -0 "${app_pid}" 2>/dev/null; then
6669
echo "error: installed app did not quit" >&2
6770
exit 1
6871
fi
69-
if ps -axo ppid=,command= | awk -v app_pid="${app_pid}" '$1 == app_pid && $2 == "/usr/bin/caffeinate" { found = 1 } END { exit !found }'; then
72+
if kill -0 "${hold_pid}" 2>/dev/null; then
7073
echo "error: installed app left its wake hold running" >&2
7174
exit 1
7275
fi
76+
assertions="$(pmset -g assertions)"
77+
if grep -q "pid ${hold_pid}(caffeinate)" <<<"${assertions}"; then
78+
echo "error: pmset retained the released wake assertion" >&2
79+
exit 1
80+
fi
7381

7482
echo "installed app launched, held wake, and quit cleanly"

0 commit comments

Comments
 (0)