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{})
| 1867 | // |
| 1868 | // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) |
| 1869 | func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool { |
| 1870 | if h, ok := t.(tHelper); ok { |
| 1871 | h.Helper() |
| 1872 | } |
| 1873 | |
| 1874 | ch := make(chan bool, 1) |
| 1875 | |
| 1876 | timer := time.NewTimer(waitFor) |
| 1877 | defer timer.Stop() |
| 1878 | |
| 1879 | ticker := time.NewTicker(tick) |
| 1880 | defer ticker.Stop() |
| 1881 | |
| 1882 | for tick := ticker.C; ; { |
| 1883 | select { |
| 1884 | case <-timer.C: |
| 1885 | return Fail(t, "Condition never satisfied", msgAndArgs...) |
| 1886 | case <-tick: |
| 1887 | tick = nil |
| 1888 | go func() { ch <- condition() }() |
| 1889 | case v := <-ch: |
| 1890 | if v { |
| 1891 | return true |
| 1892 | } |
| 1893 | tick = ticker.C |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | // CollectT implements the TestingT interface and collects all errors. |
| 1899 | type CollectT struct { |
searching dependent graphs…