MCPcopy Create free account
hub / github.com/stretchr/testify / Eventually

Function Eventually

assert/assertions.go:1930–1957  ·  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

1928//
1929// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
1930func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
1931 if h, ok := t.(tHelper); ok {
1932 h.Helper()
1933 }
1934
1935 ch := make(chan bool, 1)
1936
1937 timer := time.NewTimer(waitFor)
1938 defer timer.Stop()
1939
1940 ticker := time.NewTicker(tick)
1941 defer ticker.Stop()
1942
1943 for tick := ticker.C; ; {
1944 select {
1945 case <-timer.C:
1946 return Fail(t, "Condition never satisfied", msgAndArgs...)
1947 case <-tick:
1948 tick = nil
1949 go func() { ch <- condition() }()
1950 case v := <-ch:
1951 if v {
1952 return true
1953 }
1954 tick = ticker.C
1955 }
1956 }
1957}
1958
1959// CollectT implements the TestingT interface and collects all errors.
1960type CollectT struct {

Callers 6

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 3

TestEventuallyFalseFunction · 0.56
TestEventuallyTrueFunction · 0.56
TestEventuallyTimeoutFunction · 0.56