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: should we reuse GOMODCACHE in TestScript? #42017

Closed
mvdan opened this issue Oct 16, 2020 · 3 comments
Closed

cmd/go: should we reuse GOMODCACHE in TestScript? #42017

mvdan opened this issue Oct 16, 2020 · 3 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.

Comments

@mvdan
Copy link
Member

mvdan commented Oct 16, 2020

When a txt script file is run as a subtest, we share the host's GOCACHE by default, presumably to allow reusing the build cache and speeding up go build commands inside each test:

                "GOCACHE=" + testGOCACHE,

You can verify this easily:

        > exec env
        [stdout]
        [...]
        GOCACHE=/home/mvdan/.cache/go-build

Should we do the same with the new GOMODCACHE Go environment variable? That would let the tests share the host's module download cache.

The upside is that, for most tests, we would download and copy fewer files, even if it's just the ones in testdata/mod/.

A potential downside is that if a test relies on actual downloads happening, they'd have to unset GOMODCACHE to use an empty module download cache.

Is this worth it? Opening an issue for discussion. /cc @bcmills @jayconrod @matloob

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 16, 2020
@bcmills
Copy link
Contributor

bcmills commented Oct 16, 2020

Should we do the same with the new GOMODCACHE Go environment variable? That would let the tests share the host's module download cache.

The cmd/go tests use a local proxy, which we don't want to pollute the user's GOMODCACHE.

It would be possible, perhaps, to use a separate GOMODCACHE shared among the tests, except for a handful of tests that specifically check for caching behavior. (We didn't share the GOMODCACHE among tests initially in part due to #26794, which has long since been fixed.)

@jayconrod
Copy link
Contributor

I don't think there would be much benefit to doing this. Tests that run in -short mode don't go out to the network and just download small files from the test proxy. That's true for the majority of long tests, too. I don't think there would be much gain in test speed.

There are a number of tests that verify whether something is present in the module cache. If we used the host's module cache, those tests would need to be updated to set GOMODCACHE explicitly.

Another issue is that we sometimes change the content of modules in the test proxy. We run a test checksum database that keeps up with those changes, but we wouldn't automatically re-fetch a file in the module cache that's out of date.

@mvdan
Copy link
Member Author

mvdan commented Oct 19, 2020

Fair enough, I agree this is probably not worth it. I only thought of raising an issue because, since it's a new env var separate from GOPATH, it made the possibility easier than before.

@mvdan mvdan closed this as completed Oct 19, 2020
mvdan added a commit to mvdan/go-internal that referenced this issue Mar 12, 2021
We started making gotooltest share the host's module download cache with
test scripts, since we did it with GOCACHE and it initially made sense.

However, the upside is significantly smaller for GOMODCACHE compared to
GOCACHE. The build cache can save a significant amount of time, since
many tools have to load or build Go packages as part of their tests.
In contrast, few tests download modules, and those which do tend to
download those modules from a local proxy like goproxytest, which is
very fast already.

The downsides of sharing the module download cache are a few:

* We don't share GOPATH, and since the default GOMODCACHE is
  GOPATH/pkg/mod, sharing one and not the other is unexpected and
  inconsistent.

* Upstream testscript shares GOCACHE, but does not share GOMODCACHE.
  See golang/go#42017.

* Losing a degree of isolation in the tests is a downside in itself,
  especially given that sharing GOMODCACHE isn't crucial.

This reverts commit c5fd45a.

Note that we keep the env.txt test in place, just flipping the
expectation that GOMODCACHE does not contain ${WORK}.
myitcv pushed a commit to rogpeppe/go-internal that referenced this issue Mar 12, 2021
We started making gotooltest share the host's module download cache with
test scripts, since we did it with GOCACHE and it initially made sense.

However, the upside is significantly smaller for GOMODCACHE compared to
GOCACHE. The build cache can save a significant amount of time, since
many tools have to load or build Go packages as part of their tests.
In contrast, few tests download modules, and those which do tend to
download those modules from a local proxy like goproxytest, which is
very fast already.

The downsides of sharing the module download cache are a few:

* We don't share GOPATH, and since the default GOMODCACHE is
  GOPATH/pkg/mod, sharing one and not the other is unexpected and
  inconsistent.

* Upstream testscript shares GOCACHE, but does not share GOMODCACHE.
  See golang/go#42017.

* Losing a degree of isolation in the tests is a downside in itself,
  especially given that sharing GOMODCACHE isn't crucial.

This reverts commit c5fd45a.

Note that we keep the env.txt test in place, just flipping the
expectation that GOMODCACHE does not contain ${WORK}.
@golang golang locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants