-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
This may or may not be a bug. While investigating a gopls test that fails when using a go.work file, I noticed that the value of GOWORK is apparently not used in the test cache key:
$ go clean -cache
$ go test ./internal/lsp/safetoken
--- FAIL: TestGoplsSourceDoesNotCallTokenFileMethods (0.02s)
safetoken_test.go:89: err: exit status 1: stderr: go: -mod may only be set to readonly when in workspace mode, but it is set to "mod"
Remove the -mod flag to use the default readonly value,
or set GOWORK=off to disable workspace mode.
FAIL
FAIL golang.org/x/tools/gopls/internal/lsp/safetoken 0.036s
FAIL
$ GOWORK=off go test ./internal/lsp/safetoken
ok golang.org/x/tools/gopls/internal/lsp/safetoken 3.252s
$ go test ./internal/lsp/safetoken
ok golang.org/x/tools/gopls/internal/lsp/safetoken (cached)
Observe that we get a cache hit for the successful test run when GOWORK=off is set, even when GOWORK=off is not set.
If I had to guess, I'd say that there is an assumption that GOWORK values affect the build list, and therefore if GOWORK changes the build list will change, and therefore we don't need to hash the actual GOWORK value into the cache key. However, as we see here this may not be sufficient if the test in question actually invokes the Go command. (note that my GOWORK uses exactly x/tools and x/tools/gopls, so there is likely no difference in the build list when run from the gopls module, which has a replace directive for x/tools).
@bcmills @matloob what do you think? Should the value of GOWORK be part of the cache key? If not, please feel free to close this issue.