test: Add wait_for() shell helper

Add a shell helper function to wait for some command to succeed - typically
a test for something to be done by a background process.  Use it in the
context code which waits for the guest to respond to ssh-over-vsock
connections.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2022-09-26 20:43:36 +10:00 committed by Stefano Brivio
parent 8978f6552b
commit 05a2c7ae3c
2 changed files with 9 additions and 3 deletions

View file

@ -63,9 +63,7 @@ EOF
echo "ssh -F ${__ssh} ${__name}" > "${__enter}" echo "ssh -F ${__ssh} ${__name}" > "${__enter}"
# Wait for the guest to be booted and accepting connections # Wait for the guest to be booted and accepting connections
while ! ssh -F "${__ssh}" "${__name}" :; do wait_for ssh -F "${__ssh}" "${__name}" :
sleep 0.1
done
} }
# context_teardown() - Remove a context (leave log files intact) # context_teardown() - Remove a context (leave log files intact)

View file

@ -123,3 +123,11 @@ get_info_cols() {
__j=$((__j + 1)) __j=$((__j + 1))
done done
} }
# wait_for() - Retry a command until it succeeds
# $@: Command to run
wait_for() {
while ! "$@"; do
sleep 0.1 || sleep 1
done
}