internal/lsp: disable completion time budget in tests

Now a budget of 0 disables mean unlimited and tests no longer set the
budget. Hopefully the deep completion tests will stop flaking.

Updates golang/go#34617

Change-Id: Icdff5e78dcf1cc3d3fcbf0326716b39b00f0a8c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203338
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Muir Manders 2019-10-24 21:57:53 -07:00 committed by Rebecca Stambler
parent 2077df3685
commit cf891b754e
4 changed files with 3 additions and 12 deletions

View File

@ -3,7 +3,6 @@ package lsp
import (
"strings"
"testing"
"time"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
@ -30,7 +29,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
list := r.callCompletion(t, src, source.CompletionOptions{
Placeholders: placeholders,
Deep: true,
Budget: 5 * time.Second,
FuzzyMatching: true,
})
got := tests.FindItem(list, *items[expected.CompletionItem])
@ -59,7 +57,6 @@ func (r *runner) UnimportedCompletion(t *testing.T, src span.Span, test tests.Co
func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completion, items tests.CompletionItems) {
got := r.callCompletion(t, src, source.CompletionOptions{
Deep: true,
Budget: 5 * time.Second,
Documentation: true,
})
if !strings.Contains(string(src.URI()), "builtins") {
@ -75,7 +72,6 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
got := r.callCompletion(t, src, source.CompletionOptions{
FuzzyMatching: true,
Deep: true,
Budget: 5 * time.Second,
})
if !strings.Contains(string(src.URI()), "builtins") {
got = tests.FilterBuiltins(got)
@ -103,7 +99,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
got := r.callCompletion(t, src, source.CompletionOptions{
FuzzyMatching: true,
Deep: true,
Budget: 5 * time.Second,
})
want := expected(t, test, items)
if msg := tests.CheckCompletionOrder(want, got); msg != "" {
@ -121,6 +116,7 @@ func expected(t *testing.T, test tests.Completion, items tests.CompletionItems)
}
return want
}
func (r *runner) callCompletion(t *testing.T, src span.Span, options source.CompletionOptions) []protocol.CompletionItem {
t.Helper()

View File

@ -107,7 +107,7 @@ func (c *completer) shouldPrune() bool {
}
// Check our remaining budget every 100 candidates.
if c.deepState.candidateCount%100 == 0 {
if c.opts.Budget > 0 && c.deepState.candidateCount%100 == 0 {
spent := float64(time.Since(c.startTime)) / float64(c.opts.Budget)
switch {

View File

@ -119,7 +119,7 @@ type CompletionOptions struct {
// requests finish in a couple milliseconds, but in some cases deep
// completions can take much longer. As we use up our budget we
// dynamically reduce the search scope to ensure we return timely
// results.
// results. Zero means unlimited.
Budget time.Duration
}

View File

@ -14,7 +14,6 @@ import (
"sort"
"strings"
"testing"
"time"
"golang.org/x/tools/go/packages/packagestest"
"golang.org/x/tools/internal/lsp/cache"
@ -113,7 +112,6 @@ func (r *runner) CompletionSnippet(t *testing.T, src span.Span, expected tests.C
_, list := r.callCompletion(t, src, source.CompletionOptions{
Placeholders: placeholders,
Deep: true,
Budget: 5 * time.Second,
})
got := tests.FindItem(list, *items[expected.CompletionItem])
want := expected.PlainSnippet
@ -148,7 +146,6 @@ func (r *runner) DeepCompletion(t *testing.T, src span.Span, test tests.Completi
}
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
Deep: true,
Budget: 5 * time.Second,
Documentation: true,
})
if !strings.Contains(string(src.URI()), "builtins") {
@ -175,7 +172,6 @@ func (r *runner) FuzzyCompletion(t *testing.T, src span.Span, test tests.Complet
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
FuzzyMatching: true,
Deep: true,
Budget: 5 * time.Second,
})
if !strings.Contains(string(src.URI()), "builtins") {
list = tests.FilterBuiltins(list)
@ -220,7 +216,6 @@ func (r *runner) RankCompletion(t *testing.T, src span.Span, test tests.Completi
prefix, list := r.callCompletion(t, src, source.CompletionOptions{
FuzzyMatching: true,
Deep: true,
Budget: 5 * time.Second,
})
fuzzyMatcher := fuzzy.NewMatcher(prefix)
var got []protocol.CompletionItem