diff --git a/gopls/internal/regtest/codelens/codelens_test.go b/gopls/internal/regtest/codelens/codelens_test.go index ad35a299114..38721fb2c60 100644 --- a/gopls/internal/regtest/codelens/codelens_test.go +++ b/gopls/internal/regtest/codelens/codelens_test.go @@ -292,6 +292,13 @@ func TestGCDetails(t *testing.T) { t.Skipf("the gc details code lens doesn't work on Android") } + // TestGCDetails seems to suffer from poor performance on certain builders. + // Give it as long as it needs to complete. + timeout := 60 * time.Second + if d, ok := testenv.Deadline(t); ok { + timeout = time.Until(d) * 19 / 20 // Leave 5% headroom for cleanup. + } + const mod = ` -- go.mod -- module mod.com @@ -311,8 +318,7 @@ func main() { CodeLenses: map[string]bool{ "gc_details": true, }}, - // TestGCDetails seems to suffer from poor performance on certain builders. Give it some more time to complete. - Timeout(60*time.Second), + Timeout(timeout), ).Run(t, mod, func(t *testing.T, env *Env) { env.OpenFile("main.go") env.ExecuteCodeLensCommand("main.go", command.GCDetails) diff --git a/internal/testenv/testenv.go b/internal/testenv/testenv.go index 2a7b2a6a6dd..b3812326499 100644 --- a/internal/testenv/testenv.go +++ b/internal/testenv/testenv.go @@ -15,6 +15,7 @@ import ( "runtime" "strings" "sync" + "time" exec "golang.org/x/sys/execabs" ) @@ -307,3 +308,15 @@ func SkipAfterGo1Point(t Testing, x int) { t.Skipf("running Go version %q is version 1.%d, newer than maximum 1.%d", runtime.Version(), Go1Point(), x) } } + +// Deadline returns the deadline of t, if known, +// using the Deadline method added in Go 1.15. +func Deadline(t Testing) (time.Time, bool) { + td, ok := t.(interface { + Deadline() (time.Time, bool) + }) + if !ok { + return time.Time{}, false + } + return td.Deadline() +}