diff --git a/src/codex.bash b/src/codex.bash index 97961a4..06d6bf3 100644 --- a/src/codex.bash +++ b/src/codex.bash @@ -102,7 +102,9 @@ cdx_get_spr() { } cdx_launch_node() { - _cdx_ensure_outputs 0 || return 1 + local node_index="$1" + + _cdx_ensure_outputs "${node_index}" || return 1 local codex_cmd codex_cmd=$(cdx_cmdline "$@") || return 1 @@ -112,9 +114,19 @@ cdx_launch_node() { pm_job_exit $? )& pm_track_last_job - _cdx_pids[$1]=$! + _cdx_pids[$node_index]=$! - cdx_ensure_ready "$@" + cdx_ensure_ready "$node_index" +} + +cdx_launch_network() { + local node_count="$1" bootstrap_spr + cdx_launch_node 0 || return 1 + bootstrap_spr=$(cdx_get_spr 0) || return 1 + for i in $(seq 1 "$node_count"); do + cdx_launch_node "$i" "--bootstrap-node" "$bootstrap_spr" || return 1 + done + return 0 } cdx_pid() { diff --git a/src/utils.bash b/src/utils.bash index 3405f02..fa8e3bd 100644 --- a/src/utils.bash +++ b/src/utils.bash @@ -38,6 +38,13 @@ await() { 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 4a08348..27999a6 100755 --- a/test/test_codex.bats +++ b/test/test_codex.bats @@ -121,6 +121,28 @@ setup() { pm_stop } +@test "should launch a Codex network and allow uploading and downloading" { + pm_start + + assert cdx_launch_network 5 + + filename=$(cdx_generate_file 10) + cid=$(cdx_upload_file 0 "$filename") + + handles=() + for i in {1..4}; do + handles+=($(cdx_download_file_async "$i" "$cid")) + done + + assert await_all "${handles[@]}" + + for i in {1..4}; do + assert cdx_check_download 0 "$i" "$cid" + done + + pm_stop +} + teardown() { clh_clear_outputs } \ No newline at end of file