Skip to content

Commit 3b1e0ce

Browse files
committed
Wait for rewatch test watchers to exit
1 parent a5b0402 commit 3b1e0ce

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

rewatch/tests/lock.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ else
9090
cat rewatch.log
9191
exit 1
9292
fi
93+
94+
exit_watcher

rewatch/tests/utils.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,29 @@ replace() {
5151
fi
5252
}
5353

54+
wait_for_pid_gone() {
55+
local pid="$1"; local timeout="${2:-10}"
56+
while kill -0 "$pid" 2> /dev/null && [ "$timeout" -gt 0 ]; do
57+
sleep 1
58+
timeout=$((timeout - 1))
59+
done
60+
! kill -0 "$pid" 2> /dev/null
61+
}
62+
5463
exit_watcher() {
64+
local watcher_pid=""
65+
if [ -f lib/watch.lock ]; then
66+
watcher_pid=$(cat lib/watch.lock)
67+
fi
68+
5569
rm -f lib/watch.lock
70+
71+
if [ -n "$watcher_pid" ]; then
72+
if ! wait_for_pid_gone "$watcher_pid" 10; then
73+
error "Watcher process $watcher_pid did not exit after watch.lock was removed"
74+
return 1
75+
fi
76+
fi
5677
}
5778

5879
clear_locks() {

0 commit comments

Comments
 (0)