mirror of https://github.com/stretchr/testify.git
parent
a88bf7aab8
commit
f1bd0923b8
|
@ -1503,24 +1503,26 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t
|
|||
h.Helper()
|
||||
}
|
||||
|
||||
ch := make(chan bool, 1)
|
||||
|
||||
timer := time.NewTimer(waitFor)
|
||||
ticker := time.NewTicker(tick)
|
||||
checkPassed := make(chan bool)
|
||||
defer timer.Stop()
|
||||
|
||||
ticker := time.NewTicker(tick)
|
||||
defer ticker.Stop()
|
||||
defer close(checkPassed)
|
||||
for {
|
||||
|
||||
for tick := ticker.C; ; {
|
||||
select {
|
||||
case <-timer.C:
|
||||
return Fail(t, "Condition never satisfied", msgAndArgs...)
|
||||
case result := <-checkPassed:
|
||||
if result {
|
||||
return false
|
||||
case <-tick:
|
||||
tick = nil
|
||||
go func() { ch <- condition() }()
|
||||
case v := <-ch:
|
||||
if v {
|
||||
return true
|
||||
}
|
||||
case <-ticker.C:
|
||||
go func() {
|
||||
checkPassed <- condition()
|
||||
}()
|
||||
tick = ticker.C
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1985,3 +1985,12 @@ func TestEventuallyTrue(t *testing.T) {
|
|||
|
||||
True(t, Eventually(t, condition, 100*time.Millisecond, 20*time.Millisecond))
|
||||
}
|
||||
|
||||
func TestEventuallyIssue805(t *testing.T) {
|
||||
mockT := new(testing.T)
|
||||
|
||||
NotPanics(t, func() {
|
||||
condition := func() bool { <-time.After(time.Millisecond); return true }
|
||||
False(t, Eventually(mockT, condition, time.Millisecond, time.Microsecond))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue