From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: Re: [PATCH 01/12] test: Add wait_for() shell helper Date: Sat, 24 Sep 2022 01:07:46 +0200 Message-ID: <20220924010746.6577473f@elisabeth> In-Reply-To: <20220923072038.1667106-2-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1793219967467852315==" --===============1793219967467852315== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On Fri, 23 Sep 2022 17:20:27 +1000 David Gibson wrote: > 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 > --- > test/lib/context | 4 +--- > test/lib/util | 8 ++++++++ > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/test/lib/context b/test/lib/context > index 43b00dd..ee6b683 100644 > --- a/test/lib/context > +++ b/test/lib/context > @@ -63,9 +63,7 @@ EOF > echo "ssh -F ${__ssh} ${__name}" > "${__enter}" > > # Wait for the guest to be booted and accepting connections > - while ! ssh -F "${__ssh}" "${__name}" :; do > - sleep 0.1 > - done > + wait_for ssh -F "${__ssh}" "${__name}" : > } > > # context_teardown() - Remove a context (leave log files intact) > diff --git a/test/lib/util b/test/lib/util > index dee6c8d..72023ab 100755 > --- a/test/lib/util > +++ b/test/lib/util > @@ -123,3 +123,11 @@ get_info_cols() { > __j=$((__j + 1)) > done > } > + > +# wait_for() - Retry a command until it succeeds > +# $@: Command to run > +wait_for() { > + while ! "$@"; do > + sleep 0.1 While at it, could we replace this with sleep 0.1 || sleep 1, just in case we happen to run in an environment not supporting sleep 0.1? -- Stefano --===============1793219967467852315==--