MCPcopy
hub / github.com/expr-lang/expr / EventuallyWithT

Function EventuallyWithT

internal/testify/assert/assertions.go:1941–1980  ·  view source on GitHub ↗

EventuallyWithT asserts that given condition will be met in waitFor time, periodically checking target function each tick. In contrast to Eventually, it supplies a CollectT to the condition function, so that the condition function can use the CollectT to call other assertions. The condition is consi

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

Source from the content-addressed store, hash-verified

1939// assert.True(c, externalValue, "expected 'externalValue' to be true")
1940// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
1941func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
1942 if h, ok := t.(tHelper); ok {
1943 h.Helper()
1944 }
1945
1946 var lastFinishedTickErrs []error
1947 ch := make(chan []error, 1)
1948
1949 timer := time.NewTimer(waitFor)
1950 defer timer.Stop()
1951
1952 ticker := time.NewTicker(tick)
1953 defer ticker.Stop()
1954
1955 for tick := ticker.C; ; {
1956 select {
1957 case <-timer.C:
1958 for _, err := range lastFinishedTickErrs {
1959 t.Errorf("%v", err)
1960 }
1961 return Fail(t, "Condition never satisfied", msgAndArgs...)
1962 case <-tick:
1963 tick = nil
1964 go func() {
1965 collect := new(CollectT)
1966 defer func() {
1967 ch <- collect.errors
1968 }()
1969 condition(collect)
1970 }()
1971 case errs := <-ch:
1972 if len(errs) == 0 {
1973 return true
1974 }
1975 // Keep the errors from the last ended condition, so that they can be copied to t if timeout is reached.
1976 lastFinishedTickErrs = errs
1977 tick = ticker.C
1978 }
1979 }
1980}
1981
1982// Never asserts that the given condition doesn't satisfy in waitFor time,
1983// periodically checking the target function each tick.

Calls 3

FailFunction · 0.70
ErrorfMethod · 0.65
HelperMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…