diff --git a/src/clh b/src/clh index 3e3aeb2..c67bd7d 100644 --- a/src/clh +++ b/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" \ No newline at end of file +source "${LIB_SRC}/codex.bash" diff --git a/src/codex.bash b/src/codex.bash index 3647d57..2ae1a7d 100644 --- a/src/codex.bash +++ b/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 diff --git a/src/config.bash b/src/config.bash deleted file mode 100644 index f7ae262..0000000 --- a/src/config.bash +++ /dev/null @@ -1,2 +0,0 @@ -LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)} -OUTPUTS=${OUTPUTS:-${LIB_SRC}/../outputs} \ No newline at end of file diff --git a/src/experiment.bash b/src/experiment.bash new file mode 100644 index 0000000..888281a --- /dev/null +++ b/src/experiment.bash @@ -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 +} diff --git a/src/procmon.bash b/src/procmon.bash index a896790..c0a1963 100644 --- a/src/procmon.bash +++ b/src/procmon.bash @@ -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)" diff --git a/src/prometheus.bash b/src/prometheus.bash index 3e91aa7..4a10307 100644 --- a/src/prometheus.bash +++ b/src/prometheus.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" diff --git a/src/utils.bash b/src/utils.bash index 49779ba..7ca14d2 100644 --- a/src/utils.bash +++ b/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 } \ No newline at end of file diff --git a/test/test_codex.bats b/test/test_codex.bats index 3924c72..8042248 100755 --- a/test/test_codex.bats +++ b/test/test_codex.bats @@ -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 } diff --git a/test/test_experiment.bats b/test/test_experiment.bats new file mode 100644 index 0000000..51aeb91 --- /dev/null +++ b/test/test_experiment.bats @@ -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 +# } + diff --git a/test/test_helper/common_setup.bash b/test/test_helper/common_setup.bash index 5410157..07826b0 100644 --- a/test/test_helper/common_setup.bash +++ b/test/test_helper/common_setup.bash @@ -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" }