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 with low ticks cause panic: send on closed channel #805

Closed
pgarneau opened this issue Aug 19, 2019 · 1 comment · Fixed by #808
Closed

assert.Eventually with low ticks cause panic: send on closed channel #805

pgarneau opened this issue Aug 19, 2019 · 1 comment · Fixed by #808
Labels
assert.Eventually About assert.Eventually/EventuallyWithT bug pkg-assert Change related to package testify/assert

Comments

@pgarneau
Copy link

Setup

If you put an:
assert.Eventually(t, func() bool { return true }, time.Millisecond, 50 * time.Microsecond) inside your test, you will get flaky results and more often then not, you will get a panic:
panic: send on closed channel

Workaround

Increasing the tick to around 100 * time.Microsecond removes the flakyness

Solution

Add a waitgroup potentially so that this channel close waits for the gofunc writing to the channel completes.

jszwec added a commit to jszwec/testify that referenced this issue Aug 29, 2019
jszwec added a commit to jszwec/testify that referenced this issue Aug 29, 2019
@perhallgren
Copy link

Same for me. To reproduce:

go version

go version go1.13 darwin/amd64

go.mod

module reqtest

go 1.13

require github.com/stretchr/testify v1.4.0

req_test.go

package main

import (
	"testing"
	"time"

	"github.com/stretchr/testify/require"
)

func Test_Eventually(t *testing.T) {
	require.Eventually(t, func() bool { return true }, time.Millisecond, time.Microsecond)
}

go test req_test.go

--- FAIL: Test_Eventually (0.00s)
panic: send on closed channel

jszwec added a commit to jszwec/testify that referenced this issue Nov 6, 2019
georgelesica-wf pushed a commit that referenced this issue Nov 6, 2019
Teelevision pushed a commit to pace/bricks that referenced this issue Mar 10, 2020
The version we were using had a bug in the Eventually function that affected the routine package.
stretchr/testify#805
@dolmen dolmen added bug pkg-assert Change related to package testify/assert assert.Eventually About assert.Eventually/EventuallyWithT labels Jul 31, 2023
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
Development

Successfully merging a pull request may close this issue.

3 participants