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

cmd/go: go test takes extra time to run even for packages that do not have any test files #17248

Closed
cyli opened this issue Sep 27, 2016 · 2 comments

Comments

@cyli
Copy link

cyli commented Sep 27, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/cyli/Go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v9/wzpq8hm56b943960j1qrnblm0000gp/T/go-build685341822=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

time go test $(go list ./... | grep -v vendor)
time go test $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)

What did you expect to see?

I expected they would take the same mostly the same amount of time

What did you see instead?

time go test $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor) is reliably faster. I've also tried running time for i in {1..10}; do <command>; done and on average it is faster than not first excluding the packages without tests.

This is the case even if -parallel # is set, whether or not -race or if coverage numbers are generated. For instance, when running the tests for https://github.com/docker/swarmkit:

$  time go test -parallel 8 -race $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
...
real    0m17.380s
user    0m51.668s
sys 0m7.717s

$  time go test -parallel 8 -race $(go list ./... | grep -v vendor)
...
real    0m27.161s
user    1m26.491s
sys 0m15.368s

$  time go test $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
...
real    0m15.005s
user    0m41.354s
sys 0m6.796s

$  time go test $(go list  ./... | grep -v vendor)
...
real    0m26.743s
user    1m4.753s
sys 0m13.017s

In case time is excluding how long go list takes:

$  time (go list  ./... | grep -v vendor)
...
real    0m0.308s
user    0m0.239s
sys 0m0.136s

$  time (go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
...
real    0m0.318s
user    0m0.248s
sys 0m0.141s

I'm not sure if this is the issue, but maybe go test can automatically exclude packages provided to it that don't have tests first, and not even start building the test binary for those?

@minux
Copy link
Member

minux commented Sep 27, 2016 via email

@minux minux changed the title go test takes extra time to run even for packages that do not have any test files cmd/go: go test takes extra time to run even for packages that do not have any test files Sep 27, 2016
@minux minux closed this as completed Sep 27, 2016
@cyli
Copy link
Author

cyli commented Sep 27, 2016

Oh, that makes sense. Thanks for linking the other issue!

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

3 participants