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

tests: update + enable check for leaked goroutines #4026

Merged
merged 3 commits into from
Dec 20, 2015

Conversation

jonboulle
Copy link
Contributor

Go 1.4 landed a new testing.M type 1 which allows for start-up and
shutdown hooks when running tests. The standard library now uses this
for checking for leaked goroutines in net/http 2.

This patch essentially re-ports the updated code from the net/http test
(we were using an older version of it) - in detail:

  • updates the test to use TestMain instead of relying on
    TestGoroutinesRunning to be implicitly run after all other tests
  • adds a few new goroutines to the list of exceptions (the test itself,
    as well as the golang/glog package and pkg/log.MergeLogger, both of
    which spin off goroutines to handle log flushing/merging respectively)
  • removes a couple of TODOs in the test for extra goroutines that's run
    after individual tests (one of these re-enables the http package's
    .readLoop and the other was an out-of-date TODO)
  • re-enables the test

@jonboulle
Copy link
Contributor Author

Works fine locally, let's see what semaphore has to say..

@xiang90
Copy link
Contributor

xiang90 commented Dec 19, 2015

@jonboulle I think go 14 might still fail? The leaky issue is fixed in go 15 if I remember correctly. I will double check.

@jonboulle
Copy link
Contributor Author

Semaphore is fine and I'm using 1.4. What's the leak you have in mind? readloop?

@xiang90
Copy link
Contributor

xiang90 commented Dec 19, 2015

@jonboulle This golang/go#10457 is fixed in 15.

@jonboulle
Copy link
Contributor Author

@xiang90 how about this?

Go 1.4 landed a new testing.M type [1][1] which allows for start-up and
shutdown hooks when running tests. The standard library now uses this
for checking for leaked goroutines in net/http [2][2].

This patch essentially re-ports the updated code from the net/http test
(we were using an older version of it) - in detail:
- updates the test to use `TestMain` instead of relying on
  `TestGoroutinesRunning` to be implicitly run after all other tests
- adds a few new goroutines to the list of exceptions (the test itself,
  as well as the golang/glog package and pkg/log.MergeLogger, both of
  which spin off goroutines to handle log flushing/merging respectively)
- removes a couple of TODOs in the test for extra goroutines that's run
  after individual tests (one of these re-enables the http package's
  `.readLoop` and the other was an out-of-date TODO)
- re-enables the test

[1]: https://golang.org/pkg/testing/#M
[2]: https://github.com/golang/go/blob/release-branch.go1.4/src/net/http/main_test.go#L18
func init() {
var major, minor int
var discard string
i, err := fmt.Sscanf(runtime.Version(), "go%d.%d%s", &major, &minor, &discard)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go tip version does not follow this and it is greater than 1.5. but i am fine with not testing go tip.

@xiang90
Copy link
Contributor

xiang90 commented Dec 20, 2015

LGTM! Thanks for fixing this!

jonboulle added a commit that referenced this pull request Dec 20, 2015
tests: update + enable check for leaked goroutines
@jonboulle jonboulle merged commit 98c1745 into etcd-io:master Dec 20, 2015
jonboulle added a commit to jonboulle/rkt that referenced this pull request Dec 22, 2015
Go 1.4 landed a new testing.M type [1][1] which allows for start-up and
shutdown hooks when running tests. The standard library now uses this
for checking for leaked goroutines in net/http [2][2].

This patch re-ports the updated code from the net/http test. For a
previous example, see etcd-io/etcd#4026

[1]: https://golang.org/pkg/testing/#M
[2]: https://github.com/golang/go/blob/release-branch.go1.4/src/net/http/main_test.go#L18
jonboulle added a commit to jonboulle/rkt that referenced this pull request Dec 23, 2015
Go 1.4 landed a new testing.M type [1][1] which allows for start-up and
shutdown hooks when running tests. The standard library now uses this
for checking for leaked goroutines in net/http [2][2].

This patch re-ports the updated code from the net/http test. For a
previous example, see etcd-io/etcd#4026

[1]: https://golang.org/pkg/testing/#M
[2]: https://github.com/golang/go/blob/release-branch.go1.4/src/net/http/main_test.go#L18
jonboulle added a commit to jonboulle/rkt that referenced this pull request Jan 19, 2016
Go 1.4 landed a new testing.M type [1][1] which allows for start-up and
shutdown hooks when running tests. The standard library now uses this
for checking for leaked goroutines in net/http [2][2].

This patch re-ports the updated code from the net/http test. For a
previous example, see etcd-io/etcd#4026

[1]: https://golang.org/pkg/testing/#M
[2]: https://github.com/golang/go/blob/release-branch.go1.4/src/net/http/main_test.go#L18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants