Skip to content

Commit

Permalink
lib: improve wait.For returns. (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored May 14, 2021
1 parent e3d7c85 commit c53c3d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions platform/wait/wait.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wait

import (
"errors"
"fmt"
"time"

Expand All @@ -16,6 +17,9 @@ func For(msg string, timeout, interval time.Duration, f func() (bool, error)) er
for {
select {
case <-timeUp:
if lastErr == nil {
return errors.New("time limit exceeded")
}
return fmt.Errorf("time limit exceeded: last error: %w", lastErr)
default:
}
Expand Down
3 changes: 2 additions & 1 deletion platform/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ func TestForTimeout(t *testing.T) {
})
}()

timeout := time.After(5 * time.Second)
timeout := time.After(6 * time.Second)
select {
case <-timeout:
t.Fatal("timeout exceeded")
case err := <-c:
if err == nil {
t.Errorf("expected timeout error; got %v", err)
}
t.Logf("%v", err)
}
}

0 comments on commit c53c3d0

Please sign in to comment.