Merge pull request #7448 from dtolnay/timeout
Timing out is not success
This commit is contained in:
commit
ad27190852
|
@ -36,12 +36,20 @@ func Retry(timeout time.Duration, f RetryFunc) error {
|
|||
},
|
||||
}
|
||||
|
||||
c.WaitForState()
|
||||
_, waitErr := c.WaitForState()
|
||||
|
||||
// Need to acquire the lock here to be able to avoid race using resultErr as
|
||||
// the return value
|
||||
resultErrMu.Lock()
|
||||
defer resultErrMu.Unlock()
|
||||
|
||||
// resultErr may be nil because the wait timed out and resultErr was never
|
||||
// set; this is still an error
|
||||
if resultErr == nil {
|
||||
return waitErr
|
||||
}
|
||||
// resultErr takes precedence over waitErr if both are set because it is
|
||||
// more likely to be useful
|
||||
return resultErr
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,20 @@ func TestRetry_timeout(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRetry_hang(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f := func() *RetryError {
|
||||
time.Sleep(2 * time.Second)
|
||||
return nil
|
||||
}
|
||||
|
||||
err := Retry(1*time.Second, f)
|
||||
if err == nil {
|
||||
t.Fatal("should error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetry_error(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue