mirror of
https://github.com/logos-storage/logos-storage-local-harness.git
synced 2026-01-07 16:03:08 +00:00
feat: add PID tracking test
This commit is contained in:
parent
93187c6a91
commit
0c6f2b3b34
7
src/clh
Normal file
7
src/clh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||||
|
|
||||||
|
source "${LIB_SRC}/config.bash"
|
||||||
|
source "${LIB_SRC}/utils.bash"
|
||||||
|
source "${LIB_SRC}/process_monitor.bash"
|
||||||
@ -33,13 +33,11 @@ clh_start_process_monitor() {
|
|||||||
(
|
(
|
||||||
shutdown=false
|
shutdown=false
|
||||||
while ! $shutdown; do
|
while ! $shutdown; do
|
||||||
for pid_file in "${_procmon_output}"/*.pid; do
|
clh_get_tracked_pids
|
||||||
[[ -f "${pid_file}" ]] || continue # null glob
|
for pid in "${result[@]}"; do
|
||||||
base_name=$(basename "${pid_file}")
|
|
||||||
pid=${base_name%.pid}
|
|
||||||
if ! kill -0 "${pid}"; then
|
if ! kill -0 "${pid}"; then
|
||||||
echoerr "[procmon] ${pid} is dead"
|
echoerr "[procmon] ${pid} is dead"
|
||||||
rm "${pid_file}"
|
rm "${_procmon_output}/${pid}.pid"
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
@ -60,6 +58,7 @@ clh_track_last_background_job() {
|
|||||||
clh_get_tracked_pids() {
|
clh_get_tracked_pids() {
|
||||||
result=()
|
result=()
|
||||||
for pid_file in "${_procmon_output}"/*.pid; do
|
for pid_file in "${_procmon_output}"/*.pid; do
|
||||||
|
[[ -f "${pid_file}" ]] || continue # null glob
|
||||||
base_name=$(basename "${pid_file}")
|
base_name=$(basename "${pid_file}")
|
||||||
pid=${base_name%.pid}
|
pid=${base_name%.pid}
|
||||||
result+=("${pid}")
|
result+=("${pid}")
|
||||||
@ -80,7 +79,7 @@ clh_stop_process_monitor() {
|
|||||||
if [ "$1" = "monitor_only" ]; then
|
if [ "$1" = "monitor_only" ]; then
|
||||||
echoerr "[procmon] stop monitor only. Children will be left behind."
|
echoerr "[procmon] stop monitor only. Children will be left behind."
|
||||||
kill -s TERM "$_procmon_pid"
|
kill -s TERM "$_procmon_pid"
|
||||||
wait "$_procmon_pid"
|
await "$_procmon_pid"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
echoerr "[procmon] stop process group. This will halt the script."
|
echoerr "[procmon] stop process group. This will halt the script."
|
||||||
|
|||||||
@ -11,4 +11,11 @@ clh_output_folder() {
|
|||||||
|
|
||||||
echoerr() {
|
echoerr() {
|
||||||
echo "$@" >&2
|
echo "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
await() {
|
||||||
|
local pid=$1
|
||||||
|
while kill -0 "$pid"; do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
}
|
}
|
||||||
@ -18,29 +18,48 @@ setup() {
|
|||||||
refute clh_stop_process_monitor
|
refute clh_stop_process_monitor
|
||||||
}
|
}
|
||||||
|
|
||||||
# @test "should keep track of process PIDs" {
|
@test "should keep track of process IDs" {
|
||||||
# clh_get_tracked_pids
|
echo "hi"
|
||||||
# assert [ ${#result[@]} -eq 0 ]
|
assert clh_start_process_monitor
|
||||||
|
|
||||||
# (
|
clh_get_tracked_pids
|
||||||
# while [ ! -f "${OUTPUT_FOLDER}/stop" ]; do
|
assert [ ${#result[@]} -eq 0 ]
|
||||||
# sleep 0.1
|
|
||||||
# done
|
|
||||||
# ) &
|
|
||||||
# clh_track_last_background_job
|
|
||||||
|
|
||||||
# (
|
(
|
||||||
# while [ ! -f "${OUTPUT_FOLDER}/stop" ]; do
|
while true; do
|
||||||
# sleep 0.1
|
sleep 0.1
|
||||||
# done
|
done
|
||||||
# ) &
|
) &
|
||||||
# clh_track_last_background_job
|
clh_track_last_background_job
|
||||||
|
p1=$!
|
||||||
|
|
||||||
# clh_get_tracked_pids
|
(
|
||||||
# assert [ ${#result[@]} -eq 2 ]
|
while true; do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
) &
|
||||||
|
clh_track_last_background_job
|
||||||
|
p2=$!
|
||||||
|
|
||||||
# touch "${OUTPUT_FOLDER}/stop"
|
clh_get_tracked_pids
|
||||||
|
assert [ ${#result[@]} -eq 2 ]
|
||||||
|
|
||||||
# clh_get_tracked_pids
|
kill -s TERM "$p1"
|
||||||
# assert [ ${#result[@]} -eq 0 ]
|
kill -s TERM "$p2"
|
||||||
# }
|
|
||||||
|
echo "Kill issued" > killissued
|
||||||
|
|
||||||
|
# This will hang the bats runner for some reason.
|
||||||
|
await "$p1"
|
||||||
|
await "$p2"
|
||||||
|
|
||||||
|
# This should be more than enough for the process monitor to
|
||||||
|
# catch the exits. The alternative would be implementing temporal
|
||||||
|
# predicates.
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
clh_get_tracked_pids
|
||||||
|
assert [ ${#result[@]} -eq 0 ]
|
||||||
|
|
||||||
|
clh_stop_process_monitor "monitor_only"
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user