Skip to content

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

@broady

Description

@broady
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions