forked from TrueCloudLab/lego
lib: improve wait.For returns. (#1403)
This commit is contained in:
parent
e3d7c85cfc
commit
c53c3d08db
2 changed files with 6 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package wait
|
package wait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -16,6 +17,9 @@ func For(msg string, timeout, interval time.Duration, f func() (bool, error)) er
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeUp:
|
case <-timeUp:
|
||||||
|
if lastErr == nil {
|
||||||
|
return errors.New("time limit exceeded")
|
||||||
|
}
|
||||||
return fmt.Errorf("time limit exceeded: last error: %w", lastErr)
|
return fmt.Errorf("time limit exceeded: last error: %w", lastErr)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func TestForTimeout(t *testing.T) {
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
timeout := time.After(5 * time.Second)
|
timeout := time.After(6 * time.Second)
|
||||||
select {
|
select {
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
t.Fatal("timeout exceeded")
|
t.Fatal("timeout exceeded")
|
||||||
|
@ -21,5 +21,6 @@ func TestForTimeout(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected timeout error; got %v", err)
|
t.Errorf("expected timeout error; got %v", err)
|
||||||
}
|
}
|
||||||
|
t.Logf("%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue