mirror of
https://github.com/logos-storage/logos-storage-local-harness.git
synced 2026-01-03 14:03:07 +00:00
feat: refactor and add experiment base
This commit is contained in:
parent
6533970ebb
commit
75ee562d2f
4
src/clh
4
src/clh
@ -2,11 +2,9 @@
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/config.bash
|
||||
source "${LIB_SRC}/config.bash"
|
||||
# shellcheck source=./src/utils.bash
|
||||
source "${LIB_SRC}/utils.bash"
|
||||
# shellcheck source=./src/procmon.bash
|
||||
source "${LIB_SRC}/procmon.bash"
|
||||
# shellcheck source=./src/codex.bash
|
||||
source "${LIB_SRC}/codex.bash"
|
||||
source "${LIB_SRC}/codex.bash"
|
||||
|
||||
@ -3,8 +3,6 @@ set -o pipefail
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/config.bash
|
||||
source "${LIB_SRC}/config.bash"
|
||||
# shellcheck source=./src/utils.bash
|
||||
source "${LIB_SRC}/utils.bash"
|
||||
# shellcheck source=./src/procmon.bash
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
OUTPUTS=${OUTPUTS:-${LIB_SRC}/../outputs}
|
||||
18
src/experiment.bash
Normal file
18
src/experiment.bash
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/utils.bash
|
||||
source "${LIB_SRC}/utils.bash"
|
||||
|
||||
exp_start() {
|
||||
_experiment_type="$1"
|
||||
# FIXME: this is pretty clumsy/confusing. We're "initing" the
|
||||
# harness just so it sets the base output folder, and then
|
||||
# "initing" it again.
|
||||
if [ -z "${_clh_output}" ]; then
|
||||
clh_init
|
||||
fi
|
||||
|
||||
clh_init "${_clh_output}/${_experiment_type}-$(date +%s)-${RANDOM}" || return 1
|
||||
}
|
||||
@ -9,8 +9,6 @@ set -o pipefail
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/config.bash
|
||||
source "${LIB_SRC}/config.bash"
|
||||
# shellcheck source=./src/utils.bash
|
||||
source "${LIB_SRC}/utils.bash"
|
||||
|
||||
@ -223,6 +221,26 @@ pm_async() {
|
||||
result=("$!")
|
||||
}
|
||||
|
||||
await() {
|
||||
local pid=$1 timeout=${2:-30} start="${SECONDS}"
|
||||
while kill -0 "$pid" 2> /dev/null; do
|
||||
if ((SECONDS - start > timeout)); then
|
||||
echoerr "Error: timeout waiting for process $pid to exit"
|
||||
return 1
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
echoerr "Process $pid exited"
|
||||
return 0
|
||||
}
|
||||
|
||||
await_all() {
|
||||
local pids=("$@") timeout=${2:-30}
|
||||
for pid in "${pids[@]}"; do
|
||||
await "$pid" "$timeout" || return 1
|
||||
done
|
||||
}
|
||||
|
||||
_pm_job_started() {
|
||||
local pid=$1 proc_type=$2
|
||||
echoerr "[procmon] job started: $pid ($proc_type)"
|
||||
|
||||
@ -3,8 +3,6 @@ set -o pipefail
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/config.bash
|
||||
source "${LIB_SRC}/config.bash"
|
||||
# shellcheck source=./src/utils.bash
|
||||
source "${LIB_SRC}/utils.bash"
|
||||
|
||||
|
||||
@ -1,51 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o pipefail
|
||||
|
||||
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
|
||||
|
||||
# shellcheck source=./src/config.bash
|
||||
source "${LIB_SRC}/config.bash"
|
||||
|
||||
if ! command -v sha1sum > /dev/null; then
|
||||
echoerr "Error: sha1sum is required for computing file hashes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OUTPUTS=${OUTPUTS:-$(mktemp -d)} || exit 1
|
||||
OUTPUTS=$(realpath "$OUTPUTS") || exit 1
|
||||
|
||||
clh_output_folder() {
|
||||
echo "${OUTPUTS}/$1"
|
||||
clh_init() {
|
||||
_clh_output=${1:-$(mktemp -d)} || exit 1
|
||||
_clh_output=$(realpath "$_clh_output") || exit 1
|
||||
mkdir -p "${_clh_output}" || exit 1
|
||||
export _clh_output
|
||||
}
|
||||
|
||||
clh_clear_outputs() {
|
||||
rm -rf "${OUTPUTS}" || true
|
||||
clh_output_folder() {
|
||||
echo "${_clh_output}/$1"
|
||||
}
|
||||
|
||||
clh_destroy() {
|
||||
rm -rf "${_clh_output}" || true
|
||||
}
|
||||
|
||||
echoerr() {
|
||||
echo "$@" >&2
|
||||
}
|
||||
|
||||
await() {
|
||||
local pid=$1 timeout=${2:-30} start="${SECONDS}"
|
||||
while kill -0 "$pid" 2> /dev/null; do
|
||||
if ((SECONDS - start > timeout)); then
|
||||
echoerr "Error: timeout waiting for process $pid to exit"
|
||||
return 1
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
echoerr "Process $pid exited"
|
||||
return 0
|
||||
}
|
||||
|
||||
await_all() {
|
||||
local pids=("$@") timeout=${2:-30}
|
||||
for pid in "${pids[@]}"; do
|
||||
await "$pid" "$timeout" || return 1
|
||||
done
|
||||
}
|
||||
|
||||
sha1() {
|
||||
sha1sum "$1" | cut -d ' ' -f 1 || return 1
|
||||
}
|
||||
@ -196,21 +196,6 @@ setup() {
|
||||
done < "${_cdx_output}/experiment-0.csv"
|
||||
}
|
||||
|
||||
# @test "should add a prometheus target for each Codex node when requested" {
|
||||
# pm_start
|
||||
|
||||
# cdx_enable_prometheus "anexperiment" "84858"
|
||||
|
||||
# cdx_launch_node 0
|
||||
# config_file="${_prom_output}/8290-anexperiment-84858-node-1-codex.json"
|
||||
# assert [ -f "$config_file" ]
|
||||
|
||||
# cdx_destroy_node 0
|
||||
# assert [ ! -f "$config_file" ]
|
||||
|
||||
# pm_stop
|
||||
# }
|
||||
|
||||
teardown() {
|
||||
clh_clear_outputs
|
||||
clh_destroy
|
||||
}
|
||||
|
||||
36
test/test_experiment.bats
Normal file
36
test/test_experiment.bats
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bats
|
||||
# shellcheck disable=SC2128
|
||||
setup() {
|
||||
load test_helper/common_setup
|
||||
common_setup
|
||||
|
||||
# shellcheck source=./src/experiment.bash
|
||||
source "${LIB_SRC}/experiment.bash"
|
||||
}
|
||||
|
||||
@test "should create experiment folder and set it as the global harness output" {
|
||||
output_base="${_clh_output}"
|
||||
|
||||
exp_start "experiment-type"
|
||||
experiment_output="${output_base}/experiment-type-[0-9]+-[0-9]+"
|
||||
|
||||
[[ "${_clh_output}" =~ ${experiment_output} ]]
|
||||
|
||||
assert [ -d "${_clh_output}" ]
|
||||
}
|
||||
|
||||
# @test "should add a prometheus target for each Codex node when requested" {
|
||||
# pm_start
|
||||
|
||||
# cdx_enable_prometheus "anexperiment" "84858"
|
||||
|
||||
# cdx_launch_node 0
|
||||
# config_file="${_prom_output}/8290-anexperiment-84858-node-1-codex.json"
|
||||
# assert [ -f "$config_file" ]
|
||||
|
||||
# cdx_destroy_node 0
|
||||
# assert [ ! -f "$config_file" ]
|
||||
|
||||
# pm_stop
|
||||
# }
|
||||
|
||||
@ -4,4 +4,8 @@ common_setup() {
|
||||
load test_helper/bats-assert/load
|
||||
|
||||
export LIB_SRC="${BATS_TEST_DIRNAME}/../src"
|
||||
|
||||
# shellcheck source=./src/clh
|
||||
source "${LIB_SRC}/clh"
|
||||
clh_init "${LIB_SRC}/../test_outputs"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user