Skip to content

Commit 0283753

Browse files
committed
cmd/go/internal/modfetch/codehost: fix flaky TestReadZip
In normal use by the go command, ReadZip always happens after Stat, which makes sure that the relevant revision has been fetched to local disk. But TestReadZip calls ReadZip directly, and ReadZip was not ensuring that fetch had happened. This made 'go test' pass (because other earlier tests had done Stat of the hg test repo) but 'go test -run=ReadZip' fail by itself. And on big enough machines, the tests that were doing the Stat were running in parallel with ReadZip, causing non-deterministic failures depending on whether the Stat completed before ReadZip started. Fix the race by calling Stat directly in ReadZip, like we already do in ReadFile. Fixes longtest builder flake. Change-Id: Ib42f64876b7ef51d8148c616539b412b42f8b24e Reviewed-on: https://go-review.googlesource.com/c/go/+/720280 Reviewed-by: David Chase <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 4ebf295 commit 0283753

File tree

1 file changed

+8
-3
lines changed
  • src/cmd/go/internal/modfetch/codehost

1 file changed

+8
-3
lines changed

src/cmd/go/internal/modfetch/codehost/vcs.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,20 @@ func (r *vcsRepo) ReadZip(ctx context.Context, rev, subdir string, maxSize int64
624624
return nil, vcsErrorf("vcs %s: ReadZip: %w", r.cmd.vcs, errors.ErrUnsupported)
625625
}
626626

627+
if rev == "latest" {
628+
rev = r.cmd.latest
629+
}
630+
_, err = r.Stat(ctx, rev) // download rev into local repo
631+
if err != nil {
632+
return nil, err
633+
}
634+
627635
unlock, err := r.mu.Lock()
628636
if err != nil {
629637
return nil, err
630638
}
631639
defer unlock()
632640

633-
if rev == "latest" {
634-
rev = r.cmd.latest
635-
}
636641
f, err := os.CreateTemp("", "go-readzip-*.zip")
637642
if err != nil {
638643
return nil, err

0 commit comments

Comments
 (0)