Skip to content

Commit 2f3d4ad

Browse files
adonovangopherbot
authored andcommitted
go/packages: add variant of TestRmdirAfterGoList without gocommand
This CL adds the test in the first patchset of CL 647516, which executes go list directly, thus providing a control for the substantial gocommand wrapper package. Updates golang/go#71544 Updates golang/go#73481 Change-Id: I3dbc91cb1144bd5cafbd438817a17abda1c811ae Reviewed-on: https://go-review.googlesource.com/c/tools/+/667857 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]>
1 parent cd9151d commit 2f3d4ad

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

go/packages/packages_test.go

+46-16
Original file line numberDiff line numberDiff line change
@@ -3408,8 +3408,51 @@ func writeTree(t *testing.T, archive string) string {
34083408
// finished. It is intended to evaluate the hypothesis (to explain
34093409
// issue #71544) that the go command, on Windows, occasionally fails
34103410
// to release all its handles to the temporary directory even when it
3411-
// should have finished. If this test ever fails, the go command has a bug.
3412-
func TestRmdirAfterGoList(t *testing.T) {
3411+
// should have finished.
3412+
//
3413+
// If this test ever fails, the combination of the gocommand package
3414+
// and the go command itself has a bug.
3415+
func TestRmdirAfterGoList_Runner(t *testing.T) {
3416+
testRmdirAfterGoList(t, func(ctx context.Context, dir string) {
3417+
var runner gocommand.Runner
3418+
stdout, stderr, friendlyErr, err := runner.RunRaw(ctx, gocommand.Invocation{
3419+
Verb: "list",
3420+
Args: []string{"-json", "example.com/p"},
3421+
WorkingDir: dir,
3422+
})
3423+
if ctx.Err() != nil {
3424+
return // don't report error if canceled
3425+
}
3426+
if err != nil || friendlyErr != nil {
3427+
t.Fatalf("go list failed: %v, %v (stdout=%s stderr=%s)",
3428+
err, friendlyErr, stdout, stderr)
3429+
}
3430+
})
3431+
}
3432+
3433+
// TestRmdirAfterGoList_Direct is a variant of
3434+
// TestRmdirAfterGoList_Runner that executes go list directly, to
3435+
// control for the substantial logic of the gocommand package.
3436+
//
3437+
// If this test ever fails, the go command itself has a bug.
3438+
func TestRmdirAfterGoList_Direct(t *testing.T) {
3439+
testRmdirAfterGoList(t, func(ctx context.Context, dir string) {
3440+
cmd := exec.Command("go", "list", "-json", "example.com/p")
3441+
cmd.Dir = dir
3442+
cmd.Stdout = new(strings.Builder)
3443+
cmd.Stderr = new(strings.Builder)
3444+
err := cmd.Run()
3445+
if ctx.Err() != nil {
3446+
return // don't report error if canceled
3447+
}
3448+
if err != nil {
3449+
t.Fatalf("go list failed: %v (stdout=%s stderr=%s)",
3450+
err, cmd.Stdout, cmd.Stderr)
3451+
}
3452+
})
3453+
}
3454+
3455+
func testRmdirAfterGoList(t *testing.T, f func(ctx context.Context, dir string)) {
34133456
testenv.NeedsExec(t)
34143457

34153458
dir := t.TempDir()
@@ -3428,23 +3471,10 @@ func TestRmdirAfterGoList(t *testing.T) {
34283471
}
34293472
}
34303473

3431-
runner := gocommand.Runner{}
3432-
34333474
g, ctx := errgroup.WithContext(context.Background())
34343475
for range 10 {
34353476
g.Go(func() error {
3436-
stdout, stderr, friendlyErr, err := runner.RunRaw(ctx, gocommand.Invocation{
3437-
Verb: "list",
3438-
Args: []string{"-json", "example.com/p"},
3439-
WorkingDir: dir,
3440-
})
3441-
if ctx.Err() != nil {
3442-
return nil // don't report error if canceled
3443-
}
3444-
if err != nil || friendlyErr != nil {
3445-
t.Fatalf("go list failed: %v, %v (stdout=%s stderr=%s)",
3446-
err, friendlyErr, stdout, stderr)
3447-
}
3477+
f(ctx, dir)
34483478
// Return an error so that concurrent invocations are canceled.
34493479
return fmt.Errorf("oops")
34503480
})

0 commit comments

Comments
 (0)