Re: [PATCH net-next 1/4] selftests/net/forwarding: add slowwait functions

Hangbin Liu
2024-01-26T09:22:06Z

Hi Przemek,

Thanks for your review.

On Wed, Jan 24, 2024 at 02:25:57PM +0100, Przemek Kitszel wrote:
> > +# timeout in seconds
> > +slowwait()
> > +{
> > + local timeout=$1; shift
> > +
> > + local start_time="$(date -u +%s)"
> > + while true
> > + do
> > + local out
> > + out=$("$@")
> > + local ret=$?
> > + if ((!ret)); then
>
> it would be nice to have some exit code used (or just reserved) for
> "operation failed, no need to wait, fail the test please"
> similar to the xargs, eg:
> 126 if the command cannot be run

Return directly instead of wait may confuse the caller. Maybe we can
add a parameter and let user decide whether to wait if return some value.
e.g.

slowwait nowait 126 $timeout $commands

>
> > + echo -n "$out"
> > + return 0
> > + fi
> > +
> > + local current_time="$(date -u +%s)"
> > + if ((current_time - start_time > timeout)); then
> > + echo -n "$out"
> > + return 1
> > + fi
> > +
> > + sleep 1
>
> I see that `sleep 1` is simplest correct impl, but it's tempting to
> suggest exponential back-off, perhaps with saturation at 15
>
> (but then you will have to cap last sleep to don't exceed timeout by
> more than 1).

Do you mean sleep longer when cmd exec failed? I'm not sure if it's a good
idea as the caller still wants to return ASAP when cmd exec succeeds.

Thanks
Hangbin