lntest/wait: handle the case where the pred func hangs

This commit fixes a bug in the wait.NoError function. If the predicate
function, f, passed to the NoError function would hang for the full
timeout, then the `predErr` would remain nil and so a nil error would be
returned from the function. This commit handles that case.
This commit is contained in:
Elle Mouton 2023-03-06 13:10:43 +02:00
parent 5330b3e414
commit de961af5c6
No known key found for this signature in database
GPG Key ID: D7D916376026F177

View File

@ -58,6 +58,13 @@ func NoError(f func() error, timeout time.Duration) error {
// If f() doesn't succeed within the timeout, return the last
// encountered error.
if err := Predicate(pred, timeout); err != nil {
// Handle the case where the passed in method, f, hangs for the
// full timeout
if predErr == nil {
return fmt.Errorf("method did not return within the " +
"timeout")
}
return predErr
}