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

testing: parallel starts tests even when -parallel=1 #15069

Closed
broady opened this issue Apr 1, 2016 · 5 comments
Closed

testing: parallel starts tests even when -parallel=1 #15069

broady opened this issue Apr 1, 2016 · 5 comments
Milestone

Comments

@broady
Copy link
Contributor

broady commented Apr 1, 2016

package main

import (
    "testing"
    "time"
)

func TestOne(t *testing.T) {
    tt(t)
}

func TestTwo(t *testing.T) {
    tt(t)
}

func TestThree(t *testing.T) {
    tt(t)
}

func tt(t *testing.T) {
    t.Parallel()
    time.Sleep(time.Second)
}
$ go test -timeout=1s -v
=== RUN   TestOne
=== RUN   TestTwo
=== RUN   TestThree
--- PASS: TestThree (1.00s)
--- PASS: TestTwo (1.00s)
--- PASS: TestOne (1.00s)
PASS
ok      github.com/broady/testtimeout   1.010s
$ go test -timeout=1s -parallel=1 -v
=== RUN   TestOne
=== RUN   TestTwo
=== RUN   TestThree
panic: test timed out after 1s
<snip>
exit status 2
FAIL    github.com/broady/testtimeout   1.016s

It looks like the test runner "starts" the timer for the tests even though the test code doesn't start executing. This results in a faulty test timeout.

go version devel +edb19aa Fri Mar 25 18:35:15 2016 +0000 linux/amd64

@bradfitz
Copy link
Contributor

bradfitz commented Apr 4, 2016

@robpike, @mpvl?

@bradfitz bradfitz added this to the Go1.7 milestone Apr 4, 2016
@robpike
Copy link
Contributor

robpike commented Apr 5, 2016

Looks like a bug to me.

@mpvl
Copy link
Contributor

mpvl commented Apr 5, 2016

I touched this code last so I'll take it.

@mpvl mpvl self-assigned this Apr 5, 2016
@mpvl
Copy link
Contributor

mpvl commented Apr 5, 2016

This seems like intended behavior to me. Note that the timeout is defined for the aggregate time of all tests:

"if positive, sets an aggregate time limit for all tests".

In the "go test -timeout=1s -v" run, all your parallel tests get run in parallel and are able to complete within the given timeout (by chance, I guess).

In the "go test -timeout=1s -parallel=1 -v" run, as the parallel test are run in sequence, it is guaranteed to panic. On my install, I see a PASS for the first test (both for an old version of go and the one including my changes). But I guess it depends on how lucky you are, as the timeout is so close to the running time.

@mpvl
Copy link
Contributor

mpvl commented Apr 5, 2016

working as intended.

@mpvl mpvl closed this as completed Apr 5, 2016
@golang golang locked and limited conversation to collaborators Apr 5, 2017
@rsc rsc unassigned mpvl Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants