@@ -3450,6 +3450,24 @@ func TestEventuallyTrue(t *testing.T) {
34503450 True (t , Eventually (t , condition , 100 * time .Millisecond , 20 * time .Millisecond ))
34513451}
34523452
3453+ func TestEventuallyFailNow (t * testing.T ) {
3454+ t .Parallel ()
3455+
3456+ mockT := new (CollectT )
3457+ state := 0
3458+ condition := func () bool {
3459+ state += 1
3460+ mockT .FailNow ()
3461+ panic ("unreachable" )
3462+ }
3463+
3464+ False (t , Eventually (mockT , condition , 100 * time .Millisecond , 20 * time .Millisecond ))
3465+ True (t , mockT .failed ())
3466+ Len (t , mockT .errors , 1 )
3467+ ErrorContains (t , mockT .errors [0 ], "Condition exited unexpectedly" )
3468+ Equal (t , 1 , state , "Expected condition to be called exactly once" )
3469+ }
3470+
34533471// errorsCapturingT is a mock implementation of TestingT that captures errors reported with Errorf.
34543472type errorsCapturingT struct {
34553473 errors []error
@@ -3543,6 +3561,24 @@ func TestEventuallyWithTFailNow(t *testing.T) {
35433561 Len (t , mockT .errors , 1 )
35443562}
35453563
3564+ func TestEventuallyWithTOuterFailNow (t * testing.T ) {
3565+ t .Parallel ()
3566+
3567+ mockT := new (CollectT )
3568+ state := 0
3569+ condition := func (collect * CollectT ) {
3570+ state += 1
3571+ mockT .FailNow ()
3572+ panic ("unreachable" )
3573+ }
3574+
3575+ False (t , EventuallyWithT (mockT , condition , 100 * time .Millisecond , 20 * time .Millisecond ))
3576+ True (t , mockT .failed ())
3577+ Len (t , mockT .errors , 1 )
3578+ ErrorContains (t , mockT .errors [0 ], "Condition exited unexpectedly" )
3579+ Equal (t , 1 , state , "Expected condition to be called exactly once" )
3580+ }
3581+
35463582// Check that a long running condition doesn't block Eventually.
35473583// See issue 805 (and its long tail of following issues)
35483584func TestEventuallyTimeout (t * testing.T ) {
@@ -3634,6 +3670,24 @@ func TestNeverFailQuickly(t *testing.T) {
36343670 False (t , Never (mockT , condition , 100 * time .Millisecond , time .Second ))
36353671}
36363672
3673+ func TestNeverFailNow (t * testing.T ) {
3674+ t .Parallel ()
3675+
3676+ mockT := new (CollectT )
3677+ counter := 0
3678+ condition := func () bool {
3679+ counter += 1
3680+ mockT .FailNow ()
3681+ panic ("unreachable" )
3682+ }
3683+
3684+ False (t , Never (mockT , condition , 100 * time .Millisecond , 20 * time .Millisecond ))
3685+ True (t , mockT .failed (), "Expected Never to mark TestingT as failed" )
3686+ Len (t , mockT .errors , 1 )
3687+ ErrorContains (t , mockT .errors [0 ], "Condition exited unexpectedly" )
3688+ Equal (t , 1 , counter , "Expected condition to be called exactly once" )
3689+ }
3690+
36373691func Test_validateEqualArgs (t * testing.T ) {
36383692 t .Parallel ()
36393693
0 commit comments