Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.5.2 / internal / regtest / stress_test.go
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.
4
5 package regtest
6
7 import (
8         "context"
9         "flag"
10         "fmt"
11         "testing"
12         "time"
13 )
14
15 // Pilosa is a repository that has historically caused significant memory
16 // problems for Gopls. We use it for a simple stress test that types
17 // arbitrarily in a file with lots of dependents.
18
19 var pilosaPath = flag.String("pilosa_path", "", "Path to a directory containing "+
20         "github.com/pilosa/pilosa, for stress testing. Do not set this unless you "+
21         "know what you're doing!")
22
23 func stressTestOptions(dir string) []RunOption {
24         return []RunOption{
25                 // Run in an existing directory, since we're trying to simulate known cases
26                 // that cause gopls memory problems.
27                 InExistingDir(dir),
28
29                 // Enable live debugging.
30                 WithDebugAddress(":8087"),
31
32                 // Skip logs as they buffer up memory unnaturally.
33                 SkipLogs(),
34                 // Similarly to logs: disable hooks so that they don't affect performance.
35                 SkipHooks(true),
36                 // The Debug server only makes sense if running in singleton mode.
37                 WithModes(Singleton),
38                 // Set a generous timeout. Individual tests should control their own
39                 // graceful termination.
40                 WithTimeout(20 * time.Minute),
41
42                 // Use the actual proxy, since we want our builds to succeed.
43                 WithGOPROXY("https://proxy.golang.org"),
44         }
45 }
46
47 func TestPilosaStress(t *testing.T) {
48         if *pilosaPath == "" {
49                 t.Skip("-pilosa_path not configured")
50         }
51         opts := stressTestOptions(*pilosaPath)
52
53         withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
54                 files := []string{
55                         "cmd.go",
56                         "internal/private.pb.go",
57                         "roaring/roaring.go",
58                         "roaring/roaring_internal_test.go",
59                         "server/handler_test.go",
60                 }
61                 for _, file := range files {
62                         env.OpenFile(file)
63                 }
64                 ctx, cancel := context.WithTimeout(env.Ctx, 10*time.Minute)
65                 defer cancel()
66
67                 i := 1
68                 // MagicNumber is an identifier that occurs in roaring.go. Just change it
69                 // arbitrarily.
70                 env.RegexpReplace("roaring/roaring.go", "MagicNumber", fmt.Sprintf("MagicNumber%d", 1))
71                 for {
72                         select {
73                         case <-ctx.Done():
74                                 return
75                         default:
76                         }
77                         env.RegexpReplace("roaring/roaring.go", fmt.Sprintf("MagicNumber%d", i), fmt.Sprintf("MagicNumber%d", i+1))
78                         time.Sleep(20 * time.Millisecond)
79                         i++
80                 }
81         })
82 }