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 Jul 22, 2023
1 parent 717dda5 commit dc3af0f
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 @@ -2816,6 +2816,42 @@ func TestEventuallyIssue805(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 dc3af0f

Please sign in to comment.