1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 . "golang.org/x/tools/gopls/internal/regtest"
17 // Pilosa is a repository that has historically caused significant memory
18 // problems for Gopls. We use it for a simple stress test that types
19 // arbitrarily in a file with lots of dependents.
21 var pilosaPath = flag.String("pilosa_path", "", "Path to a directory containing "+
22 "github.com/pilosa/pilosa, for stress testing. Do not set this unless you "+
23 "know what you're doing!")
25 func stressTestOptions(dir string) []RunOption {
27 // Run in an existing directory, since we're trying to simulate known cases
28 // that cause gopls memory problems.
31 // Enable live debugging.
32 DebugAddress(":8087"),
34 // Skip logs as they buffer up memory unnaturally.
36 // Similarly to logs: disable hooks so that they don't affect performance.
38 // The Debug server only makes sense if running in singleton mode.
40 // Set a generous timeout. Individual tests should control their own
41 // graceful termination.
42 Timeout(20 * time.Minute),
44 // Use the actual proxy, since we want our builds to succeed.
45 GOPROXY("https://proxy.golang.org"),
49 func TestPilosaStress(t *testing.T) {
50 if *pilosaPath == "" {
51 t.Skip("-pilosa_path not configured")
53 opts := stressTestOptions(*pilosaPath)
55 WithOptions(opts...).Run(t, "", func(t *testing.T, env *Env) {
58 "internal/private.pb.go",
60 "roaring/roaring_internal_test.go",
61 "server/handler_test.go",
63 for _, file := range files {
66 ctx, cancel := context.WithTimeout(env.Ctx, 10*time.Minute)
70 // MagicNumber is an identifier that occurs in roaring.go. Just change it
72 env.RegexpReplace("roaring/roaring.go", "MagicNumber", fmt.Sprintf("MagicNumber%d", 1))
79 env.RegexpReplace("roaring/roaring.go", fmt.Sprintf("MagicNumber%d", i), fmt.Sprintf("MagicNumber%d", i+1))
80 time.Sleep(20 * time.Millisecond)