mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
tests/int/helpers: reimplement wait_for_container
... by using retry, to avoid code duplication. While at it, make it check the number of arguments and error out on invalid usage. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -400,25 +400,14 @@ function retry() {
|
||||
|
||||
# retry until the given container has state
|
||||
function wait_for_container() {
|
||||
local attempts=$1
|
||||
local delay=$2
|
||||
local cid=$3
|
||||
# optionally wait for a specific status
|
||||
local wait_for_status="${4:-}"
|
||||
local i
|
||||
|
||||
for ((i = 0; i < attempts; i++)); do
|
||||
runc state $cid
|
||||
if [[ "$status" -eq 0 ]]; then
|
||||
if [[ "${output}" == *"${wait_for_status}"* ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
sleep $delay
|
||||
done
|
||||
|
||||
echo "runc state failed to return state $statecheck $attempts times. Output: $output"
|
||||
false
|
||||
if [ $# -eq 3 ]; then
|
||||
retry "$1" "$2" __runc state "$3"
|
||||
elif [ $# -eq 4 ]; then
|
||||
retry "$1" "$2" eval "__runc state $3 | grep -qw $4"
|
||||
else
|
||||
echo "Usage: wait_for_container ATTEMPTS DELAY ID [STATUS]" 1>&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function testcontainer() {
|
||||
|
||||
Reference in New Issue
Block a user