mirror of
https://github.com/logos-storage/logos-storage-local-harness.git
synced 2026-01-06 23:43:05 +00:00
feat: add no-timeout option to await; fix minor bugs
This commit is contained in:
parent
2fde22116c
commit
29a39369eb
@ -56,7 +56,7 @@ for i in $(seq 1 "${repetitions}"); do
|
|||||||
handles+=("$result")
|
handles+=("$result")
|
||||||
done
|
done
|
||||||
|
|
||||||
await_all "${handles[@]}"
|
await_all "${handles[@]}" "Inf"
|
||||||
|
|
||||||
cdx_log_timings_end
|
cdx_log_timings_end
|
||||||
done
|
done
|
||||||
|
|||||||
@ -209,6 +209,8 @@ pm_list_descendants() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pm_async() {
|
pm_async() {
|
||||||
|
_pm_assert_state "running" || return 1
|
||||||
|
|
||||||
proc_type=""
|
proc_type=""
|
||||||
command=()
|
command=()
|
||||||
while [[ "$#" -gt 0 ]]; do
|
while [[ "$#" -gt 0 ]]; do
|
||||||
@ -227,7 +229,7 @@ pm_async() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
(
|
(
|
||||||
set +e
|
set -e
|
||||||
_pm_job_started "${BASHPID}" "$proc_type" "$@"
|
_pm_job_started "${BASHPID}" "$proc_type" "$@"
|
||||||
trap '_pm_job_exited "${BASHPID}" "$proc_type" "killed" "$@"' TERM
|
trap '_pm_job_exited "${BASHPID}" "$proc_type" "killed" "$@"' TERM
|
||||||
trap '_pm_job_exited "${BASHPID}" "$proc_type" "$?" "$@"' EXIT
|
trap '_pm_job_exited "${BASHPID}" "$proc_type" "$?" "$@"' EXIT
|
||||||
@ -239,7 +241,7 @@ pm_async() {
|
|||||||
await() {
|
await() {
|
||||||
local pid=$1 timeout=${2:-30} start="${SECONDS}"
|
local pid=$1 timeout=${2:-30} start="${SECONDS}"
|
||||||
while kill -0 "$pid" 2> /dev/null; do
|
while kill -0 "$pid" 2> /dev/null; do
|
||||||
if ((SECONDS - start > timeout)); then
|
if [ "$timeout" != 'Inf' ] && ((SECONDS - start > timeout)); then
|
||||||
echoerr "Error: timeout waiting for process $pid to exit"
|
echoerr "Error: timeout waiting for process $pid to exit"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -23,7 +23,6 @@ setup() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
assert [ "$found" = true ]
|
assert [ "$found" = true ]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "should launch Codex nodes with metrics enabled when there is an experiment in scope" {
|
@test "should launch Codex nodes with metrics enabled when there is an experiment in scope" {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
# shellcheck disable=SC2128
|
# shellcheck disable=SC2128,SC2317
|
||||||
setup() {
|
setup() {
|
||||||
load test_helper/common_setup
|
load test_helper/common_setup
|
||||||
common_setup
|
common_setup
|
||||||
@ -10,6 +10,34 @@ setup() {
|
|||||||
pm_set_outputs "${TEST_OUTPUTS}/pm"
|
pm_set_outputs "${TEST_OUTPUTS}/pm"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "should allow awaiting for a process" {
|
||||||
|
job() {
|
||||||
|
sleep 0.1
|
||||||
|
}
|
||||||
|
|
||||||
|
pm_start
|
||||||
|
|
||||||
|
pm_async job
|
||||||
|
pid=$result
|
||||||
|
|
||||||
|
assert await "$pid"
|
||||||
|
pm_stop
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "should allow awaiting for a process up until a timeout" {
|
||||||
|
job() {
|
||||||
|
sleep 5000
|
||||||
|
}
|
||||||
|
|
||||||
|
pm_start
|
||||||
|
|
||||||
|
pm_async job
|
||||||
|
pid=$result
|
||||||
|
|
||||||
|
refute await "$pid" 1
|
||||||
|
pm_stop
|
||||||
|
}
|
||||||
|
|
||||||
@test "should kill processes recursively" {
|
@test "should kill processes recursively" {
|
||||||
# Note that this is fragile. We need to structure
|
# Note that this is fragile. We need to structure
|
||||||
# the process tree such that the parent does not exit
|
# the process tree such that the parent does not exit
|
||||||
@ -230,6 +258,8 @@ callback() {
|
|||||||
@test "should allow passing custom arguments to lifecycle callback" {
|
@test "should allow passing custom arguments to lifecycle callback" {
|
||||||
pm_register_callback "sleepy" "callback"
|
pm_register_callback "sleepy" "callback"
|
||||||
|
|
||||||
|
pm_start
|
||||||
|
|
||||||
pm_async sleep 0.1 -%- "sleepy" "arg1" "arg2"
|
pm_async sleep 0.1 -%- "sleepy" "arg1" "arg2"
|
||||||
pid=$result
|
pid=$result
|
||||||
|
|
||||||
@ -237,4 +267,6 @@ callback() {
|
|||||||
|
|
||||||
assert_equal "$(cat "${_pm_output}/${pid}-sleepy-start-args")" "arg1 arg2"
|
assert_equal "$(cat "${_pm_output}/${pid}-sleepy-start-args")" "arg1 arg2"
|
||||||
assert_equal "$(cat "${_pm_output}/${pid}-sleepy-exit-args")" "arg1 arg2"
|
assert_equal "$(cat "${_pm_output}/${pid}-sleepy-exit-args")" "arg1 arg2"
|
||||||
|
|
||||||
|
pm_stop
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user