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

Does not work with go 1.7 #9

Closed
ghaering opened this issue Aug 17, 2016 · 10 comments
Closed

Does not work with go 1.7 #9

ghaering opened this issue Aug 17, 2016 · 10 comments

Comments

@ghaering
Copy link

With Go 1.7, there is always a leaked Gorouting reported, even for empty tests:

func TestStoppedSlotReporter(t *testing.T) {
defer leaktest.Check(t)()
}

@fortytw2
Copy link
Owner

What platform are you on? All the tests pass for me on go version go1.7 darwin/amd64

@ghaering
Copy link
Author

To make sure I did the experiment again on a host that has never seen any Go toolchain before. Linux amd64 is the platform:

root@es02 /tmp/src # go version
go version go1.7 linux/amd64
root@es02 /tmp/src # cat foo_test.go
package main

import (
"testing"
"github.com/fortytw2/leaktest"
)

func TestFoo(t _testing.T) {
defer leaktest.Check(t)()
}
root@es02 /tmp/src # go test foo_test.go
--- FAIL: TestFoo (5.04s)
leaktest.go:86: Leaked goroutine: goroutine 1 [chan receive]:
testing.(_T).Run(0xc4200780c0, 0x50ed19, 0x7, 0x51d838, 0xc42003fd30)
/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200780c0)
/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200780c0, 0xc420045e30)
/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x51d858, 0x593220, 0x1, 0x1, 0x50ffa2)
/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc420045ef8, 0xc42000a510)
/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
command-line-arguments/_test/_testmain.go:54 +0xc6
FAIL
FAIL command-line-arguments 5.043s

@fortytw2
Copy link
Owner

Very odd - travis tests all seem ok - just added that function to the test suite in b3d1133d076449571b3ca0a795b14dd5f8af28ae, will take a look later on a linux platform, specifically which OS?

@ghaering
Copy link
Author

The OS does not matter here. I work on Arch Linux where I saw the problem, but my output from above was on Ubuntu 14.04 where I reproduced it to make sure it is not a local issue with the Go installation.

@ghaering
Copy link
Author

If you have Docker installed on your Mac, here's a quick way to reproduce the bug:

➜ bug docker build -t bug .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM golang:1.7
---> fe25c00086fb
Step 2 : ADD foo_test.go /go/src/
---> Using cache
---> c3a3ee696ae8
Step 3 : RUN go get github.com/fortytw2/leaktest
---> Using cache
---> c14875d4b8cf
Step 4 : WORKDIR /go/src
---> Using cache
---> f2005c068308
Step 5 : CMD go test foo_test.go
---> Using cache
---> 57b5ff02e15a
Successfully built 57b5ff02e15a
➜ bug docker run -ti bug
--- FAIL: TestFoo (5.03s)
leaktest.go:86: Leaked goroutine: goroutine 1 [chan receive]:
testing.(_T).Run(0xc4200980c0, 0x50ed19, 0x7, 0x51d838, 0xc42003bd30)
/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200980c0)
/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200980c0, 0xc420040e30)
/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x51d858, 0x593220, 0x1, 0x1, 0x50ffa2)
/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(_M).Run(0xc420040ef8, 0xc4200723f0)
/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
command-line-arguments/_test/_testmain.go:54 +0xc6
FAIL
FAIL command-line-arguments 5.033s

bug.zip

@ghaering
Copy link
Author

Just found out: -race actually hides the bug. Run the tests without -race to see it!

@fortytw2
Copy link
Owner

Hmm, added a test to travis that doesn't use -race, https://travis-ci.org/fortytw2/leaktest/jobs/153383478

Will boot up my other computer in a bit and test this out, can't replicate locally on OS X without -race 😢

@belak
Copy link

belak commented Sep 8, 2016

It looks like the tests went through a fairly large refactor. You can "fix" it by adding strings.Contains(stack, "testing.(*M).Run(") || to the list of stacks to ignore, but I'm not certain this is the correct solution. Another option would be go ignore everything from files named _testmain.go, but that doesn't seem like the right solution either because this will probably break with old versions of go.

@belak belak mentioned this issue Sep 8, 2016
@belak
Copy link

belak commented Sep 9, 2016

After playing with this more, I've been able to reproduce this when specifying a package with go test [package name]

@fortytw2
Copy link
Owner

fortytw2 commented Sep 9, 2016

ah perfect, I couldn't manage to reproduce this on any machine I had, but didn't try go test [package name], I'll try to change the travis setup to call that too so the tests fail like they should

hectorj pushed a commit to hectorj/leaktest that referenced this issue Sep 23, 2016
hectorj pushed a commit to hectorj/leaktest that referenced this issue Sep 23, 2016
fortytw2 pushed a commit that referenced this issue Sep 23, 2016
* Change Travis config to trigger issue #9

* Fix #9 by ignoring the new goroutine from testing package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants