From de961af5c6c59b9a4418391a60c79865b9ba3ed0 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 6 Mar 2023 13:10:43 +0200 Subject: [PATCH] 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. --- lntest/wait/wait.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lntest/wait/wait.go b/lntest/wait/wait.go index b6274086c..c0cd2ded2 100644 --- a/lntest/wait/wait.go +++ b/lntest/wait/wait.go @@ -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 }