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

x/tools/refactor/importgraph: running tests with GO111MODULE=on is slow and writes to GOPATH workspace #30221

Closed
dmitshur opened this issue Feb 14, 2019 · 3 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Feb 14, 2019

Can be reproduced using Go 1.11.5 on macOS:

$ ls /tmp/gopath
ls: /tmp/gopath: No such file or directory
$ export GOPATH=/tmp/gopath
$ GO111MODULE=off go get -d github.com/shurcooL/github_flavored_markdown
$ GO111MODULE=off go get -d -t golang.org/x/tools/refactor/importgraph
$ shasum /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
965892713fd48f7842527e54e9a8d63639d8afe4  /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
$ cd /tmp/gopath/src/golang.org/x/tools/refactor/importgraph

importgraph $ GO111MODULE=off go test -count=1
PASS
ok  	golang.org/x/tools/refactor/importgraph	0.337s
importgraph $ shasum /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
965892713fd48f7842527e54e9a8d63639d8afe4  /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod

importgraph $ GO111MODULE=on go test -count=1
go: creating new go.mod: module golang.org/x/tools
PASS
ok  	golang.org/x/tools/refactor/importgraph	25.369s
importgraph $ shasum /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
3bf82fbc8cf4b6b2366a5d87ab990a94af8bc1e4  /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod

Running importgraph tests in module mode should not make modifications inside the user's GOPATH workspace. Fortunately, it only modifies go.mod and go.sum files, which is easy to revert thanks to version control systems.

It also makes the test very slow when one's GOPATH is sizable. With my real GOPATH, it was:

tools $ GO111MODULE=off go test -short -count=1 ./refactor/importgraph
ok  	golang.org/x/tools/refactor/importgraph	1.110s
tools $ GO111MODULE=on go test -short -count=1 ./refactor/importgraph
ok  	golang.org/x/tools/refactor/importgraph	283.044s

/cc @ianthehat @matloob

@dmitshur dmitshur added Testing An issue that has been verified to require only test changes, not just a test failure. NeedsFix The path to resolution is known, but the work has not been done. labels Feb 14, 2019
@dmitshur dmitshur added this to the Unreleased milestone Feb 14, 2019
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules and removed NeedsFix The path to resolution is known, but the work has not been done. labels Feb 14, 2019
@dmitshur
Copy link
Contributor Author

dmitshur commented Mar 12, 2020

I can't reproduce this issue now with Go 1.14:

importgraph $ GO111MODULE=off go test -count=1 
PASS
ok  	golang.org/x/tools/refactor/importgraph	0.753s
importgraph $ shasum /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
965892713fd48f7842527e54e9a8d63639d8afe4  /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
importgraph $ GO111MODULE=on go test -count=1
go: downloading golang.org/x/mod v0.2.0
go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
PASS
ok  	golang.org/x/tools/refactor/importgraph	3.731s
importgraph $ shasum /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod
965892713fd48f7842527e54e9a8d63639d8afe4  /tmp/gopath/src/github.com/shurcooL/github_flavored_markdown/go.mod

There is no longer a massive difference in test timing between the two modes anymore on my real GOPATH directory with many packages:

tools $ GO111MODULE=off go test -short -count=1 ./refactor/importgraph
ok  	golang.org/x/tools/refactor/importgraph	0.714s
tools $ GO111MODULE=on go test -short -count=1 ./refactor/importgraph
ok  	golang.org/x/tools/refactor/importgraph	4.169s

So I think this is resolved. I'm not sure what change fixed it.

@matloob
Copy link
Contributor

matloob commented Mar 12, 2020

Strange. Should we close the issue?

@dmitshur
Copy link
Contributor Author

dmitshur commented Mar 12, 2020

Sure. If it comes up again or becomes important to understand better due to other reasons, we can revisit this.

@golang golang locked and limited conversation to collaborators Mar 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

3 participants