Skip to content

Commit db4c57d

Browse files
committed
gopls/internal/regtest: split regtests up into multiple packages
Regtests have gotten large, and started timing out on some slow builders. They also can't yet be run in parallel, due to some process-level shared state (e.g. gc_details). Furthermore, there seems to be some per-process resource leak that we don't yet fully understand causing slowdown as the tests progress. Address these problems by splitting the regtests up into multiple packages. This also makes it easier to run only relevant tests during development. For golang/go#42789 For golang/go#39384 Change-Id: I1a74e4c379f3a650f4c434db44f9368e527aa459 Reviewed-on: https://go-review.googlesource.com/c/tools/+/287572 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent f871472 commit db4c57d

23 files changed

+421
-262
lines changed

gopls/internal/regtest/bench_test.go renamed to gopls/internal/regtest/bench/bench_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package regtest
5+
package bench
66

77
import (
88
"flag"
99
"fmt"
1010
"testing"
1111

12+
. "golang.org/x/tools/gopls/internal/regtest"
13+
1214
"golang.org/x/tools/internal/lsp/protocol"
1315
)
1416

17+
func TestMain(m *testing.M) {
18+
Main(m)
19+
}
20+
1521
func printBenchmarkResults(result testing.BenchmarkResult) {
1622
fmt.Println("Benchmark Statistics:")
1723
fmt.Println(result.String())
@@ -37,7 +43,7 @@ func TestBenchmarkIWL(t *testing.T) {
3743

3844
results := testing.Benchmark(func(b *testing.B) {
3945
for i := 0; i < b.N; i++ {
40-
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {})
46+
WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {})
4147
}
4248
})
4349

@@ -72,7 +78,7 @@ func TestBenchmarkSymbols(t *testing.T) {
7278
}
7379
opts = append(opts, conf)
7480

75-
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
81+
WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {
7682
// We can't Await in this test, since we have disabled hooks. Instead, run
7783
// one symbol request to completion to ensure all necessary cache entries
7884
// are populated.

gopls/internal/regtest/completion_bench_test.go renamed to gopls/internal/regtest/bench/completion_bench_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package regtest
5+
package bench
66

77
import (
88
"flag"
@@ -11,6 +11,8 @@ import (
1111
"strings"
1212
"testing"
1313

14+
. "golang.org/x/tools/gopls/internal/regtest"
15+
1416
"golang.org/x/tools/internal/lsp/fake"
1517
)
1618

@@ -45,7 +47,7 @@ func benchmarkCompletion(options completionBenchOptions, t *testing.T) {
4547
// it first (and therefore need hooks).
4648
opts = append(opts, SkipHooks(false))
4749

48-
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
50+
WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {
4951
env.OpenFile(options.file)
5052

5153
// Run edits required for this completion.

gopls/internal/regtest/stress_test.go renamed to gopls/internal/regtest/bench/stress_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package regtest
5+
package bench
66

77
import (
88
"context"
99
"flag"
1010
"fmt"
1111
"testing"
1212
"time"
13+
14+
. "golang.org/x/tools/gopls/internal/regtest"
1315
)
1416

1517
// Pilosa is a repository that has historically caused significant memory
@@ -50,7 +52,7 @@ func TestPilosaStress(t *testing.T) {
5052
}
5153
opts := stressTestOptions(*pilosaPath)
5254

53-
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
55+
WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {
5456
files := []string{
5557
"cmd.go",
5658
"internal/private.pb.go",

gopls/internal/regtest/codelens_test.go renamed to gopls/internal/regtest/codelens/codelens_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package regtest
5+
package codelens
66

77
import (
88
"runtime"
99
"strings"
1010
"testing"
1111

12+
. "golang.org/x/tools/gopls/internal/regtest"
13+
1214
"golang.org/x/tools/internal/lsp/fake"
1315
"golang.org/x/tools/internal/lsp/protocol"
1416
"golang.org/x/tools/internal/lsp/source"
1517
"golang.org/x/tools/internal/lsp/tests"
1618
"golang.org/x/tools/internal/testenv"
1719
)
1820

21+
func TestMain(m *testing.M) {
22+
Main(m)
23+
}
24+
1925
func TestDisablingCodeLens(t *testing.T) {
2026
const workspace = `
2127
-- go.mod --
@@ -52,11 +58,11 @@ const (
5258
}
5359
for _, test := range tests {
5460
t.Run(test.label, func(t *testing.T) {
55-
withOptions(
61+
WithOptions(
5662
EditorConfig{
5763
CodeLenses: test.enabled,
5864
},
59-
).run(t, workspace, func(t *testing.T, env *Env) {
65+
).Run(t, workspace, func(t *testing.T, env *Env) {
6066
env.OpenFile("lib.go")
6167
lens := env.CodeLens("lib.go")
6268
if gotCodeLens := len(lens) > 0; gotCodeLens != test.wantCodeLens {
@@ -115,9 +121,9 @@ func main() {
115121
"Upgrade direct dependencies",
116122
} {
117123
t.Run(commandTitle, func(t *testing.T) {
118-
withOptions(
124+
WithOptions(
119125
ProxyFiles(proxyWithLatest),
120-
).run(t, shouldUpdateDep, func(t *testing.T, env *Env) {
126+
).Run(t, shouldUpdateDep, func(t *testing.T, env *Env) {
121127
env.OpenFile("go.mod")
122128
var lens protocol.CodeLens
123129
var found bool
@@ -195,7 +201,7 @@ func main() {
195201
_ = hi.Goodbye
196202
}
197203
`
198-
runner.Run(t, shouldRemoveDep, func(t *testing.T, env *Env) {
204+
WithOptions(ProxyFiles(proxy)).Run(t, shouldRemoveDep, func(t *testing.T, env *Env) {
199205
env.OpenFile("go.mod")
200206
env.ExecuteCodeLensCommand("go.mod", source.CommandTidy)
201207
env.Await(env.DoneWithChangeWatchedFiles())
@@ -209,7 +215,7 @@ require golang.org/x/hello v1.0.0
209215
if got != wantGoMod {
210216
t.Fatalf("go.mod tidy failed:\n%s", tests.Diff(t, wantGoMod, got))
211217
}
212-
}, ProxyFiles(proxy))
218+
})
213219
}
214220

215221
func TestRegenerateCgo(t *testing.T) {
@@ -233,7 +239,7 @@ func Foo() {
233239
print(C.fortytwo())
234240
}
235241
`
236-
runner.Run(t, workspace, func(t *testing.T, env *Env) {
242+
Run(t, workspace, func(t *testing.T, env *Env) {
237243
// Open the file. We should have a nonexistant symbol.
238244
env.OpenFile("cgo.go")
239245
env.Await(env.DiagnosticAtRegexp("cgo.go", `C\.(fortytwo)`)) // could not determine kind of name for C.fortytwo
@@ -270,12 +276,12 @@ func main() {
270276
fmt.Println(x)
271277
}
272278
`
273-
withOptions(
279+
WithOptions(
274280
EditorConfig{
275281
CodeLenses: map[string]bool{
276282
"gc_details": true,
277283
}},
278-
).run(t, mod, func(t *testing.T, env *Env) {
284+
).Run(t, mod, func(t *testing.T, env *Env) {
279285
env.OpenFile("main.go")
280286
env.ExecuteCodeLensCommand("main.go", source.CommandToggleDetails)
281287
d := &protocol.PublishDiagnosticsParams{}

gopls/internal/regtest/completion_test.go renamed to gopls/internal/regtest/completion/completion_test.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,43 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package regtest
5+
package completion
66

77
import (
88
"fmt"
99
"strings"
1010
"testing"
1111

12+
. "golang.org/x/tools/gopls/internal/regtest"
13+
1214
"golang.org/x/tools/internal/lsp/fake"
1315
"golang.org/x/tools/internal/lsp/protocol"
1416
"golang.org/x/tools/internal/testenv"
1517
)
1618

19+
func TestMain(m *testing.M) {
20+
Main(m)
21+
}
22+
23+
const proxy = `
24+
-- [email protected]/go.mod --
25+
module example.com
26+
27+
go 1.12
28+
-- [email protected]/blah/blah.go --
29+
package blah
30+
31+
const Name = "Blah"
32+
-- [email protected]/go.mod --
33+
module random.org
34+
35+
go 1.12
36+
-- [email protected]/blah/blah.go --
37+
package hello
38+
39+
const Name = "Hello"
40+
`
41+
1742
func TestPackageCompletion(t *testing.T) {
1843
testenv.NeedsGo1Point(t, 14)
1944
const files = `
@@ -123,7 +148,7 @@ pac
123148
},
124149
} {
125150
t.Run(tc.name, func(t *testing.T) {
126-
run(t, files, func(t *testing.T, env *Env) {
151+
Run(t, files, func(t *testing.T, env *Env) {
127152
if tc.content != nil {
128153
env.WriteWorkspaceFile(tc.filename, *tc.content)
129154
env.Await(
@@ -180,7 +205,7 @@ package ma
180205
`
181206

182207
want := []string{"ma", "ma_test", "main", "math", "math_test"}
183-
run(t, files, func(t *testing.T, env *Env) {
208+
Run(t, files, func(t *testing.T, env *Env) {
184209
env.OpenFile("math/add.go")
185210
completions := env.Completion("math/add.go", fake.Pos{
186211
Line: 0,
@@ -241,9 +266,9 @@ func _() {
241266
_ = blah.Hello
242267
}
243268
`
244-
withOptions(
269+
WithOptions(
245270
ProxyFiles(proxy),
246-
).run(t, mod, func(t *testing.T, env *Env) {
271+
).Run(t, mod, func(t *testing.T, env *Env) {
247272
// Make sure the dependency is in the module cache and accessible for
248273
// unimported completions, and then remove it before proceeding.
249274
env.RemoveWorkspaceFile("main2.go")
@@ -310,7 +335,7 @@ package mainmod
310335
311336
const Name = "mainmod"
312337
`
313-
withOptions(ProxyFiles(proxy)).run(t, files, func(t *testing.T, env *Env) {
338+
WithOptions(ProxyFiles(proxy)).Run(t, files, func(t *testing.T, env *Env) {
314339
env.CreateBuffer("import.go", "package pkg\nvar _ = mainmod.Name\n")
315340
env.SaveBuffer("import.go")
316341
content := env.ReadWorkspaceFile("import.go")

0 commit comments

Comments
 (0)