Skip to content

Commit

Permalink
gopls/internal/regtest/codelens: use the test's deadline instead of a…
Browse files Browse the repository at this point in the history
… hard-coded timeout

We may want to generalize this to have regtest.Run always derive the
default timeout from the test's deadline. In the meantime, this is a
more targeted fix for the specific timeout in TestGCDetails.

Fixes golang/go#49902
(Maybe.)

Change-Id: Ie15735dc7b0d462ec047d3f3d8a2eceeb4411fa0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/380496
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
Bryan C. Mills committed Jan 24, 2022
1 parent 84f205d commit 135972e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gopls/internal/regtest/codelens/codelens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"runtime"
"strings"
"sync"
"time"

exec "golang.org/x/sys/execabs"
)
Expand Down Expand Up @@ -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()
}

0 comments on commit 135972e

Please sign in to comment.