mirror of
https://github.com/golang/go
synced 2024-11-26 20:21:25 -07:00
runtime: only check whether the runtime is stale once during tests
Noticed while investigating the speed of the runtime tests, as part of debugging while Plan 9's runtime tests are timing out on GCE. Change-Id: I95f5a3d967a0b45ec1ebf10067e193f51db84e26 Reviewed-on: https://go-review.googlesource.com/2283 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
ae266aaa9d
commit
b70ddc0b51
@ -5,12 +5,14 @@
|
|||||||
package runtime_test
|
package runtime_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
@ -78,14 +80,25 @@ func executeTest(t *testing.T, templ string, data interface{}, extra ...string)
|
|||||||
return string(got)
|
return string(got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
staleRuntimeOnce sync.Once // guards init of staleRuntimeErr
|
||||||
|
staleRuntimeErr error
|
||||||
|
)
|
||||||
|
|
||||||
func checkStaleRuntime(t *testing.T) {
|
func checkStaleRuntime(t *testing.T) {
|
||||||
// 'go run' uses the installed copy of runtime.a, which may be out of date.
|
staleRuntimeOnce.Do(func() {
|
||||||
out, err := testEnv(exec.Command("go", "list", "-f", "{{.Stale}}", "runtime")).CombinedOutput()
|
// 'go run' uses the installed copy of runtime.a, which may be out of date.
|
||||||
if err != nil {
|
out, err := testEnv(exec.Command("go", "list", "-f", "{{.Stale}}", "runtime")).CombinedOutput()
|
||||||
t.Fatalf("failed to execute 'go list': %v\n%v", err, string(out))
|
if err != nil {
|
||||||
}
|
staleRuntimeErr = fmt.Errorf("failed to execute 'go list': %v\n%v", err, string(out))
|
||||||
if string(out) != "false\n" {
|
return
|
||||||
t.Fatalf("Stale runtime.a. Run 'go install runtime'.")
|
}
|
||||||
|
if string(out) != "false\n" {
|
||||||
|
staleRuntimeErr = fmt.Errorf("Stale runtime.a. Run 'go install runtime'.")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if staleRuntimeErr != nil {
|
||||||
|
t.Fatal(staleRuntimeErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user