Open timoha opened 5 years ago
CC @jayconrod
I doubt we'll get to this in Go 1.13, but I plan to do some work on the testing
package for 1.14.
Change https://golang.org/cl/185877 mentions this issue: integration_test.go: use custom parallel test code
Change https://go.dev/cl/413236 mentions this issue: testing: skip parallel tests when -failfast is enabled
Another repro case, making this clearer:
package q
import "testing"
func TestA(t *testing.T) {
t.Parallel()
t.Fatal("a")
}
func TestB(t *testing.T) {
t.Parallel()
t.Fatal("b")
}
Yields:
$ go test -v -parallel=1 -failfast ./testing_test.go
=== RUN TestA
=== PAUSE TestA
=== RUN TestB
=== PAUSE TestB
=== CONT TestA
testing_test.go:7: a
--- FAIL: TestA (0.00s)
=== CONT TestB
testing_test.go:12: b
--- FAIL: TestB (0.00s)
FAIL
FAIL command-line-arguments 0.051s
FAIL
Though I would only expect one test to be marked "FAIL".
I think the issue is that Parallel()
doesn't check shouldFailFast()
after waitParallel()
returns: https://github.com/golang/go/blob/2f6783c098696790223eae6986700868e9da0472/src/testing/testing.go#L1272
It's only checked early in Run()
: https://github.com/golang/go/blob/2f6783c098696790223eae6986700868e9da0472/src/testing/testing.go#L1463
Considering this as the solution:
t.context.waitParallel()
if shouldFailFast() {
if t.chatty != nil {
t.chatty.Updatef(t.name, "=== ABORT %s\n", t.name)
}
t.SkipNow()
return
}
Edit Tests completed:
$ ../bin/go test -v -parallel=1 -failfast ./testing_test.go
=== RUN TestA
=== PAUSE TestA
=== RUN TestB
=== PAUSE TestB
=== CONT TestA
testing_test.go:7: a
--- FAIL: TestA (0.00s)
=== ABORT TestB
--- SKIP: TestB (0.00s)
FAIL
FAIL command-line-arguments 0.003s
FAIL
It would be nice to not have this "skipped", but it's better than actually running the test code. :)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
run with
go test -v -failfast -parallel 1
returns:What did you expect to see?
TestParallel2
not continue.What did you see instead?
TestParallel2
continued execution.