@@ -3408,8 +3408,51 @@ func writeTree(t *testing.T, archive string) string {
3408
3408
// finished. It is intended to evaluate the hypothesis (to explain
3409
3409
// issue #71544) that the go command, on Windows, occasionally fails
3410
3410
// 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 )) {
3413
3456
testenv .NeedsExec (t )
3414
3457
3415
3458
dir := t .TempDir ()
@@ -3428,23 +3471,10 @@ func TestRmdirAfterGoList(t *testing.T) {
3428
3471
}
3429
3472
}
3430
3473
3431
- runner := gocommand.Runner {}
3432
-
3433
3474
g , ctx := errgroup .WithContext (context .Background ())
3434
3475
for range 10 {
3435
3476
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 )
3448
3478
// Return an error so that concurrent invocations are canceled.
3449
3479
return fmt .Errorf ("oops" )
3450
3480
})
0 commit comments