Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert.Eventually() does not fail test when the timer expires #837

Closed
ghost opened this issue Nov 7, 2019 · 3 comments · Fixed by #869
Closed

assert.Eventually() does not fail test when the timer expires #837

ghost opened this issue Nov 7, 2019 · 3 comments · Fixed by #869
Labels
assert.Eventually About assert.Eventually/EventuallyWithT bug pkg-assert Change related to package testify/assert

Comments

@ghost
Copy link

ghost commented Nov 7, 2019

assert.Eventually() returns false (and not Fail(...)) when the timer expires.

As a result, the test does not fail.

So for example, including assert.Eventually(t, func()bool{return false}, time.Second, time.Millisecond)) in your test does not cause it to fail. It will poll the function for a second, and then pass.

Is this intentional? It seems surprising, since the other assert functions cause the test to fail when the condition is not met.

@georgelesica-wf
Copy link

If I'm not mistaken, it's the require version of the functions that fail, the assertions just return a boolean and print an error. For example, see: https://github.com/stretchr/testify/blob/master/require/require.go#L17

@dmacvicar
Copy link
Contributor

As I was seeing the same, I did some experimentation:

package main

import (
	"testing"
	"time"
	"github.com/stretchr/testify/assert"
	//	"github.com/stretchr/testify/require"
)

func TestEventually(t *testing.T) {

	assert.Eventually(t, func() bool {
		return false
	}, 10 * time.Second, 1 * time.Second, "always false")

}

With v1.4.0:

duncan@linux-1cur:/space/git/testify-testcase> go test .
--- FAIL: TestEventually (10.00s)
    main_test.go:12:
                Error Trace:    main_test.go:12
                Error:          Condition never satisfied
                Test:           TestEventually
                Messages:       always false
FAIL
FAIL    github.com/dmacvicar/testify-testcase   10.004s

With v1.4.1-0.20191106224347-f1bd0923b832

duncan@linux-1cur:/space/git/testify-testcase> go test .
go: finding github.com/stretchr/testify master
ok      github.com/dmacvicar/testify-testcase   10.005s

That can be traced to f1bd092 which replaced a

return Fail(t, "Condition never satisfied", msgAndArgs...)

with

return false

@ghost
Copy link
Author

ghost commented Nov 12, 2019

If I'm not mistaken, it's the require version of the functions that fail, the assertions just return a boolean and print an error. For example, see: https://github.com/stretchr/testify/blob/master/require/require.go#L17

I don't think that's accurate. The other assert functions all return Fail(...) when the condition is not met, which causes a test failure before returning false. This one simply returns false with no call to Fail(...).

For example, in assert.Equal: https://github.com/stretchr/testify/blob/master/assert/assertions.go#L339

I'm currently working around this by calling assert.True(t, assert.Eventually(t, ...))

It looks like @dmacvicar has already opened a PR to fix this though -- #838. Thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert.Eventually About assert.Eventually/EventuallyWithT bug pkg-assert Change related to package testify/assert
Projects
None yet
3 participants