Skip to content

Commit dc3af0f

Browse files
committed
test that we succeed quickly
1 parent 717dda5 commit dc3af0f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

assert/assertions_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,42 @@ func TestEventuallyIssue805(t *testing.T) {
28162816
})
28172817
}
28182818

2819+
func TestEventuallySucceedQuickly(t *testing.T) {
2820+
mockT := new(testing.T)
2821+
2822+
condition := func() bool { <-time.After(time.Millisecond); return true }
2823+
2824+
done := make(chan struct{})
2825+
go func() {
2826+
defer close(done)
2827+
True(t, Eventually(mockT, condition, 1000*time.Millisecond, 100*time.Millisecond))
2828+
}()
2829+
2830+
select {
2831+
case <-done:
2832+
case <-time.After(10 * time.Millisecond):
2833+
Fail(t, `condition not satisfied quickly enough`)
2834+
}
2835+
}
2836+
2837+
func TestEventuallyWithTSucceedQuickly(t *testing.T) {
2838+
mockT := new(testing.T)
2839+
2840+
condition := func(t *CollectT) { <-time.After(time.Millisecond) }
2841+
2842+
done := make(chan struct{})
2843+
go func() {
2844+
defer close(done)
2845+
True(t, EventuallyWithT(mockT, condition, 1000*time.Millisecond, 100*time.Millisecond))
2846+
}()
2847+
2848+
select {
2849+
case <-done:
2850+
case <-time.After(10 * time.Millisecond):
2851+
Fail(t, `condition not satisfied quickly enough`)
2852+
}
2853+
}
2854+
28192855
func Test_validateEqualArgs(t *testing.T) {
28202856
if validateEqualArgs(func() {}, func() {}) == nil {
28212857
t.Error("non-nil functions should error")

0 commit comments

Comments
 (0)