@@ -484,8 +484,9 @@ var (
484
484
pkgArgs []string
485
485
pkgs []* load.Package
486
486
487
- testKillTimeout = 10 * time .Minute
488
- testCacheExpire time.Time // ignore cached test results before this time
487
+ testActualTimeout = 10 * time .Minute // actual timeout which is passed to tests
488
+ testKillTimeout = testActualTimeout + 1 * time .Minute // backup alarm
489
+ testCacheExpire time.Time // ignore cached test results before this time
489
490
)
490
491
491
492
// testVetFlags is the list of flags to pass to vet when invoked automatically during go test.
@@ -552,13 +553,21 @@ func runTest(cmd *base.Command, args []string) {
552
553
// the test wedges with a goroutine spinning and its background
553
554
// timer does not get a chance to fire.
554
555
if dt , err := time .ParseDuration (testTimeout ); err == nil && dt > 0 {
555
- testKillTimeout = dt + 1 * time .Minute
556
+ testActualTimeout = dt
557
+ testKillTimeout = testActualTimeout + 1 * time .Minute
556
558
} else if err == nil && dt == 0 {
557
559
// An explicit zero disables the test timeout.
560
+ // No timeout is passed to tests.
558
561
// Let it have one century (almost) before we kill it.
562
+ testActualTimeout = - 1
559
563
testKillTimeout = 100 * 365 * 24 * time .Hour
560
564
}
561
565
566
+ // Pass timeout to tests if it exists.
567
+ if testActualTimeout > 0 {
568
+ testArgs = append (testArgs , "-test.timeout=" + testActualTimeout .String ())
569
+ }
570
+
562
571
// show passing test output (after buffering) with -v flag.
563
572
// must buffer because tests are running in parallel, and
564
573
// otherwise the output will get mixed.
0 commit comments