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{})
| 1928 | // |
| 1929 | // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) |
| 1930 | func 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. |
| 1960 | type CollectT struct { |