Never asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick. assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})
| 1984 | // |
| 1985 | // assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) |
| 1986 | func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool { |
| 1987 | if h, ok := t.(tHelper); ok { |
| 1988 | h.Helper() |
| 1989 | } |
| 1990 | |
| 1991 | ch := make(chan bool, 1) |
| 1992 | |
| 1993 | timer := time.NewTimer(waitFor) |
| 1994 | defer timer.Stop() |
| 1995 | |
| 1996 | ticker := time.NewTicker(tick) |
| 1997 | defer ticker.Stop() |
| 1998 | |
| 1999 | for tick := ticker.C; ; { |
| 2000 | select { |
| 2001 | case <-timer.C: |
| 2002 | return true |
| 2003 | case <-tick: |
| 2004 | tick = nil |
| 2005 | go func() { ch <- condition() }() |
| 2006 | case v := <-ch: |
| 2007 | if v { |
| 2008 | return Fail(t, "Condition satisfied", msgAndArgs...) |
| 2009 | } |
| 2010 | tick = ticker.C |
| 2011 | } |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | // ErrorIs asserts that at least one of the errors in err's chain matches target. |
| 2016 | // This is a wrapper for errors.Is. |
searching dependent graphs…