mirror of
https://github.com/logos-storage/logos-storage-local-harness.git
synced 2026-01-08 00:13:06 +00:00
feat: add codex startup checks; check-in Codex submodule for integration tsting
This commit is contained in:
parent
c39609bfde
commit
2d2c2dda6f
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,3 +7,6 @@
|
|||||||
[submodule "test/test_helper/bats-assert"]
|
[submodule "test/test_helper/bats-assert"]
|
||||||
path = test/test_helper/bats-assert
|
path = test/test_helper/bats-assert
|
||||||
url = https://github.com/bats-core/bats-assert.git
|
url = https://github.com/bats-core/bats-assert.git
|
||||||
|
[submodule "test/codex"]
|
||||||
|
path = test/codex
|
||||||
|
url = https://github.com/codex-storage/nim-codex
|
||||||
|
|||||||
@ -15,6 +15,8 @@ _cdx_base_api_port=8080
|
|||||||
_cdx_base_disc_port=8190
|
_cdx_base_disc_port=8190
|
||||||
_cdx_base_metrics_port=8290
|
_cdx_base_metrics_port=8290
|
||||||
|
|
||||||
|
_cdx_node_start_timeout=30
|
||||||
|
|
||||||
cdx_cmdline() {
|
cdx_cmdline() {
|
||||||
local api_port\
|
local api_port\
|
||||||
disc_port\
|
disc_port\
|
||||||
@ -57,3 +59,50 @@ cdx_cmdline() {
|
|||||||
" --log-file=${_cdx_logs}/codex-${node_index}.log --data-dir=${_cdx_data}/codex-${node_index}"\
|
" --log-file=${_cdx_logs}/codex-${node_index}.log --data-dir=${_cdx_data}/codex-${node_index}"\
|
||||||
" --api-port=${api_port} --disc-port=${disc_port} --loglevel=INFO"
|
" --api-port=${api_port} --disc-port=${disc_port} --loglevel=INFO"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cdx_get_spr() {
|
||||||
|
local node_index="$1" api_port spr
|
||||||
|
api_port=$((_cdx_base_api_port + node_index))
|
||||||
|
|
||||||
|
spr=$(curl --silent --fail "http://localhost:${api_port}/api/codex/v1/debug/info" | grep -oe 'spr:[^"]\+')
|
||||||
|
if [[ -z "$spr" ]]; then
|
||||||
|
echoerr "Error: unable to get SPR for node $node_index"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${spr}"
|
||||||
|
}
|
||||||
|
|
||||||
|
cdx_launch_node() {
|
||||||
|
_check_codex_binary
|
||||||
|
|
||||||
|
local codex_cmd
|
||||||
|
codex_cmd=$(cdx_cmdline "$@")
|
||||||
|
|
||||||
|
(
|
||||||
|
$codex_cmd
|
||||||
|
pm_job_exit $?
|
||||||
|
)&
|
||||||
|
pm_track_last_job
|
||||||
|
|
||||||
|
cdx_ensure_ready "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
cdx_ensure_ready() {
|
||||||
|
local node_index="$1" timeout=${2:-$_cdx_node_start_timeout} start now
|
||||||
|
start=$(date +%s)
|
||||||
|
while true; do
|
||||||
|
if cdx_get_spr "$node_index"; then
|
||||||
|
echoerr "Codex node $node_index is ready."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
now=$(date +%s)
|
||||||
|
if (( now - start > timeout )); then
|
||||||
|
echoerr "Codex node $node_index did not start within ${timeout} seconds."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
|
}
|
||||||
1
test/codex
Submodule
1
test/codex
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e35aec78700f529ddf0c9c6764b77927a0cc0165
|
||||||
@ -33,3 +33,31 @@ setup() {
|
|||||||
" --data-dir=${_cdx_output}/data/codex-0"\
|
" --data-dir=${_cdx_output}/data/codex-0"\
|
||||||
" --api-port=8080 --disc-port=8190 --loglevel=INFO"
|
" --api-port=8080 --disc-port=8190 --loglevel=INFO"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "should fail readiness check if node is not running" {
|
||||||
|
refute cdx_ensure_ready 0 1
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "should pass readiness check if node is running" {
|
||||||
|
data_dir=$(clh_output_folder "codex-temp")
|
||||||
|
"${CODEX_BINARY}" --nat:none --data-dir="$data_dir" &> /dev/null &
|
||||||
|
pid=$!
|
||||||
|
|
||||||
|
assert cdx_ensure_ready 0 3
|
||||||
|
|
||||||
|
kill -SIGKILL "$pid"
|
||||||
|
await "$pid"
|
||||||
|
rm -rf "$data_dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
#@test "should launch a Codex node" {
|
||||||
|
# export CLH_CODEX_BINARY="${BATS_TEST_DIRNAME}/codex/build/codex"
|
||||||
|
#
|
||||||
|
# assert cdx_launch_node 0
|
||||||
|
#
|
||||||
|
# # Node must be running and ready.
|
||||||
|
# assert [ ! -z "$(cdx_get_spr 0)" ]
|
||||||
|
# # We should see a log file and a data directory.
|
||||||
|
# assert [ -f "${_cdx_output}/logs/codex-0.log" ]
|
||||||
|
# assert [ -d "${_cdx_output}/data/codex-0" ]
|
||||||
|
#}
|
||||||
@ -4,4 +4,10 @@ common_setup() {
|
|||||||
load test_helper/bats-assert/load
|
load test_helper/bats-assert/load
|
||||||
|
|
||||||
export LIB_SRC="${BATS_TEST_DIRNAME}/../src"
|
export LIB_SRC="${BATS_TEST_DIRNAME}/../src"
|
||||||
|
export CODEX_BINARY="${BATS_TEST_DIRNAME}/codex/build/codex"
|
||||||
|
|
||||||
|
if [ ! -f "$CODEX_BINARY" ]; then
|
||||||
|
echo "Codex binary not found at $CODEX_BINARY"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user