cmd/coordinator: scale go test timeout by GO_TEST_TIMEOUT_SCALE

Previously, this environment variable was used to scale test timeout
only in the main repository. Use it when running go test on packages
in other repositories too.

This unfortunately means that if some tests get so slow that they
timeout with the default go test timeout value, builders that use
timeout scale will not report such findings. Hopefully most builders
are as fast as viable, and timeout scaling is only used when there's
no other viable alternative.

Fixes golang/go#56968.

Change-Id: I84d5ab504c1bd808815ec5962f713d71dfec6758
Reviewed-on: https://go-review.googlesource.com/c/build/+/453975
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/coordinator/buildstatus.go b/cmd/coordinator/buildstatus.go
index 89ed7fd..cc3facb 100644
--- a/cmd/coordinator/buildstatus.go
+++ b/cmd/coordinator/buildstatus.go
@@ -1084,6 +1084,10 @@
 	if st.conf.IsRace() {
 		args = append(args, "-race")
 	}
+	if scale := st.conf.GoTestTimeoutScale(); scale != 1 {
+		const goTestDefaultTimeout = 10 * time.Minute // Default value taken from Go 1.20.
+		args = append(args, "-timeout="+(goTestDefaultTimeout*time.Duration(scale)).String())
+	}
 
 	var remoteErrors []error
 	for _, tr := range testRuns {
diff --git a/dashboard/builders.go b/dashboard/builders.go
index 43fb32a..04a1157 100644
--- a/dashboard/builders.go
+++ b/dashboard/builders.go
@@ -963,12 +963,12 @@
 	// up into separate dist tests or shards, like the test/ dir
 	// was)
 	d := 20 * time.Minute
-	d *= time.Duration(c.timeoutScale())
+	d *= time.Duration(c.GoTestTimeoutScale())
 	return d
 }
 
-// timeoutScale returns this builder's GO_TEST_TIMEOUT_SCALE value, or 1.
-func (c *BuildConfig) timeoutScale() int {
+// GoTestTimeoutScale returns this builder's GO_TEST_TIMEOUT_SCALE value, or 1.
+func (c *BuildConfig) GoTestTimeoutScale() int {
 	const pfx = "GO_TEST_TIMEOUT_SCALE="
 	for _, env := range [][]string{c.env, c.HostConfig().env} {
 		for _, kv := range env {