MCPcopy
hub / github.com/stretchr/testify / Eventually

Function Eventually

assert/assertions.go:1988–2021  ·  view source on GitHub ↗

Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick. assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)

(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1986//
1987// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
1988func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
1989 if h, ok := t.(tHelper); ok {
1990 h.Helper()
1991 }
1992
1993 ch := make(chan bool, 1)
1994 checkCond := func() { ch <- condition() }
1995
1996 timer := time.NewTimer(waitFor)
1997 defer timer.Stop()
1998
1999 ticker := time.NewTicker(tick)
2000 defer ticker.Stop()
2001
2002 var tickC <-chan time.Time
2003
2004 // Check the condition once first on the initial call.
2005 go checkCond()
2006
2007 for {
2008 select {
2009 case <-timer.C:
2010 return Fail(t, "Condition never satisfied", msgAndArgs...)
2011 case <-tickC:
2012 tickC = nil
2013 go checkCond()
2014 case v := <-ch:
2015 if v {
2016 return true
2017 }
2018 tickC = ticker.C
2019 }
2020 }
2021}
2022
2023// CollectT implements the TestingT interface and collects all errors.
2024type CollectT struct {

Callers 7

EventuallyFunction · 0.92
EventuallyfFunction · 0.70
TestEventuallyFalseFunction · 0.70
TestEventuallyTrueFunction · 0.70
TestEventuallyTimeoutFunction · 0.70
EventuallyMethod · 0.70

Calls 2

FailFunction · 0.70
HelperMethod · 0.65

Tested by 4

TestEventuallyFalseFunction · 0.56
TestEventuallyTrueFunction · 0.56
TestEventuallyTimeoutFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…