mirror of
https://github.com/logos-storage/logos-storage-local-harness.git
synced 2026-01-02 13:33:11 +00:00
feat: add async downloads
This commit is contained in:
parent
2781f2b9ec
commit
a3043eabc9
@ -117,9 +117,14 @@ cdx_launch_node() {
|
||||
cdx_ensure_ready "$@"
|
||||
}
|
||||
|
||||
cdx_pid() {
|
||||
local node_index="$1"
|
||||
echo "${_cdx_pids[$node_index]}"
|
||||
}
|
||||
|
||||
cdx_destroy_node() {
|
||||
local node_index="$1" wipe_data="${2:-false}" pid
|
||||
pid="${_cdx_pids[$node_index]}"
|
||||
pid="$(cdx_pid "$node_index")"
|
||||
if [ -z "$pid" ]; then
|
||||
echoerr "Error: no process ID for node $node_index"
|
||||
return 1
|
||||
@ -197,6 +202,15 @@ cdx_download_file() {
|
||||
-o "${_cdx_downloads}/codex-${node_index}/$cid" || return 1
|
||||
}
|
||||
|
||||
cdx_download_file_async() {
|
||||
(
|
||||
cdx_download_file "$@"
|
||||
pm_job_exit $?
|
||||
) &
|
||||
pm_track_last_job
|
||||
echo $!
|
||||
}
|
||||
|
||||
cdx_upload_sha1() {
|
||||
local node_index="$1" cid="$2"
|
||||
cat "${_cdx_uploads}/codex-${node_index}/${cid}.sha1" || return 1
|
||||
|
||||
@ -191,6 +191,11 @@ pm_kill_rec() {
|
||||
kill -s TERM "$descendant" 2> /dev/null || true
|
||||
done
|
||||
|
||||
# Tries to wait so processes are not left lingering.
|
||||
for descendant in "${result[@]}"; do
|
||||
await "$descendant" || echo "[procmon] failed to wait for process $descendant"
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,10 @@ clh_output_folder() {
|
||||
echo "${OUTPUTS}/$1"
|
||||
}
|
||||
|
||||
clh_clear_outputs() {
|
||||
rm -rf "${OUTPUTS}" || true
|
||||
}
|
||||
|
||||
echoerr() {
|
||||
echo "$@" >&2
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ setup() {
|
||||
pm_stop
|
||||
}
|
||||
|
||||
@test "should upload and synchronously download file to Codex node" {
|
||||
@test "should upload and synchronously download file from Codex node" {
|
||||
pm_start
|
||||
|
||||
assert cdx_launch_node 0
|
||||
@ -83,8 +83,29 @@ setup() {
|
||||
filename=$(cdx_generate_file 10)
|
||||
cid=$(cdx_upload_file 0 "$filename")
|
||||
|
||||
cdx_download_file 0 "$cid"
|
||||
assert cdx_download_file 0 "$cid"
|
||||
assert_equal $(sha1 "${filename}") $(cdx_download_sha1 0 "$cid")
|
||||
|
||||
pm_stop
|
||||
}
|
||||
|
||||
@test "should upload and asynchronously download file from Codex node" {
|
||||
pm_start
|
||||
|
||||
assert cdx_launch_node 0
|
||||
assert cdx_ensure_ready 0 3
|
||||
|
||||
filename=$(cdx_generate_file 10)
|
||||
cid=$(cdx_upload_file 0 "$filename")
|
||||
|
||||
handle=$(cdx_download_file_async 0 "$cid")
|
||||
await $handle 3
|
||||
|
||||
assert_equal $(sha1 "${filename}") $(cdx_download_sha1 0 "$cid")
|
||||
|
||||
pm_stop
|
||||
}
|
||||
|
||||
teardown() {
|
||||
clh_clear_outputs
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user