stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.53k stars 1.6k forks source link

If condition passed to Never does not return before waitFor, then the Never assertion passes. #1654

Open brackendawson opened 1 month ago

brackendawson commented 1 month ago

Description

If a condition function is passed to Never which does not return once before waitFor elapses, then the assertion passes having never completed a single check.

Never asserts that the given condition doesn't satisfy in waitFor time...

Technically this is correct, but I think our implementation of it is surprising.

Step To Reproduce

func TestIfy(t *testing.T) {
    assert.Never(t, func() bool {
        time.Sleep(2 * time.Second)
        return true // this should fail
    }, time.Millisecond, time.Second)
}

Expected behavior

The test fails because the condition is statically true

Actual behavior

Test passes

brackendawson commented 1 month ago

I'm curious what @dolmen and @cszczepaniak think about this as you were discussing in this area over the summer. I think we should make Never, Eventually and EventuallyWithT wait for the last run of their condition functions to return, it would make their behaviour consistent when they are called with unreasonably small times.