Skip to content

Commit 7ec44f8

Browse files
committed
test that we succeed quickly
1 parent 24cbf3e commit 7ec44f8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

assert/assertions_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,42 @@ func TestEventuallyTimeout(t *testing.T) {
30203020
})
30213021
}
30223022

3023+
func TestEventuallySucceedQuickly(t *testing.T) {
3024+
mockT := new(testing.T)
3025+
3026+
condition := func() bool { <-time.After(time.Millisecond); return true }
3027+
3028+
done := make(chan struct{})
3029+
go func() {
3030+
defer close(done)
3031+
True(t, Eventually(mockT, condition, 1000*time.Millisecond, 100*time.Millisecond))
3032+
}()
3033+
3034+
select {
3035+
case <-done:
3036+
case <-time.After(10 * time.Millisecond):
3037+
Fail(t, `condition not satisfied quickly enough`)
3038+
}
3039+
}
3040+
3041+
func TestEventuallyWithTSucceedQuickly(t *testing.T) {
3042+
mockT := new(testing.T)
3043+
3044+
condition := func(t *CollectT) { <-time.After(time.Millisecond) }
3045+
3046+
done := make(chan struct{})
3047+
go func() {
3048+
defer close(done)
3049+
True(t, EventuallyWithT(mockT, condition, 1000*time.Millisecond, 100*time.Millisecond))
3050+
}()
3051+
3052+
select {
3053+
case <-done:
3054+
case <-time.After(10 * time.Millisecond):
3055+
Fail(t, `condition not satisfied quickly enough`)
3056+
}
3057+
}
3058+
30233059
func Test_validateEqualArgs(t *testing.T) {
30243060
if validateEqualArgs(func() {}, func() {}) == nil {
30253061
t.Error("non-nil functions should error")

0 commit comments

Comments
 (0)