0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00
zot/test/blackbox/helpers_wait.bash

29 lines
728 B
Bash
Raw Normal View History

function wait_for_string() {
local search_term="$1"
local filepath="$2"
local wait_time="${3:-2m}"
wait_file "$filepath" 60 || { echo "server log file missing: '$filepath'"; return 1; }
wait_str "$filepath" "$search_term" "$wait_time"
}
function wait_str() {
local filepath="$1"
local search_term="$2"
local wait_time="${3:-2m}"
(timeout $wait_time tail -F -n +1 "$filepath" &) | grep -q "$search_term" && return 0
echo "timeout of $wait_time reached. unable to find '$search_term' in '$filepath'"
return 1
}
function wait_file() {
local file="$1"; shift
local wait_seconds="${1:-60}"; shift
until test $((wait_seconds--)) -eq 0 -o -f "$file" ; do sleep 1; done
}