Skip to content

Commit

Permalink
test that we succeed quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
cszczepaniak committed Jun 8, 2024
1 parent 24cbf3e commit 7ec44f8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,42 @@ func TestEventuallyTimeout(t *testing.T) {
})
}

func TestEventuallySucceedQuickly(t *testing.T) {
mockT := new(testing.T)

condition := func() bool { <-time.After(time.Millisecond); return true }

done := make(chan struct{})
go func() {
defer close(done)
True(t, Eventually(mockT, condition, 1000*time.Millisecond, 100*time.Millisecond))
}()

select {
case <-done:
case <-time.After(10 * time.Millisecond):
Fail(t, `condition not satisfied quickly enough`)
}
}

func TestEventuallyWithTSucceedQuickly(t *testing.T) {
mockT := new(testing.T)

condition := func(t *CollectT) { <-time.After(time.Millisecond) }

done := make(chan struct{})
go func() {
defer close(done)
True(t, EventuallyWithT(mockT, condition, 1000*time.Millisecond, 100*time.Millisecond))
}()

select {
case <-done:
case <-time.After(10 * time.Millisecond):
Fail(t, `condition not satisfied quickly enough`)
}
}

func Test_validateEqualArgs(t *testing.T) {
if validateEqualArgs(func() {}, func() {}) == nil {
t.Error("non-nil functions should error")
Expand Down

0 comments on commit 7ec44f8

Please sign in to comment.