Debian Codegraph @

gopls/internal/test/integration/bench/stress_test.go

raw symbols SCIP
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 bench
6
7 import (
8 "context"
9 "flag"
10 "fmt"
11 "testing"
12 "time"
13
14 "golang.org/x/tools/gopls/internal/cache"
15 "golang.org/x/tools/gopls/internal/lsprpc"
16 "golang.org/x/tools/gopls/internal/test/integration/fake"
17 "golang.org/x/tools/internal/jsonrpc2"
18 "golang.org/x/tools/internal/jsonrpc2/servertest"
19 )
20
21 // github.com/pilosa/pilosa is a repository that has historically caused
22 // significant memory problems for Gopls. We use it for a simple stress test
23 // that types arbitrarily in a file with lots of dependents.
24
25 var pilosaPath = flag.String("pilosa_path", "", "Path to a directory containing "+
26 "github.com/pilosa/pilosa, for stress testing. Do not set this unless you "+
27 "know what you're doing!")
28
29 func TestPilosaStress(t *testing.T) {
30 // TODO(rfindley): revisit this test and make it is hermetic: it should check
31 // out pilosa into a directory.
32 //
33 // Note: This stress test has not been run recently, and may no longer
34 // function properly.
35 if *pilosaPath == "" {
36 t.Skip("-pilosa_path not configured")
37 }
38
39 sandbox, err := fake.NewSandbox(&fake.SandboxConfig{
40 Workdir: *pilosaPath,
41 GOPROXY: "https://proxy.golang.org",
42 })
43 if err != nil {
44 t.Fatal(err)
45 }
46 server := lsprpc.NewStreamServer(cache.New(nil), false, nil)
47 ts := servertest.NewPipeServer(server, jsonrpc2.NewRawStream)
48
49 ctx := context.Background()
50 editor, err := fake.NewEditor(sandbox, fake.EditorConfig{}).Connect(ctx, ts, fake.ClientHooks{})
51 if err != nil {
52 t.Fatal(err)
53 }
54
55 files := []string{
56 "cmd.go",
57 "internal/private.pb.go",
58 "roaring/roaring.go",
59 "roaring/roaring_internal_test.go",
60 "server/handler_test.go",
61 }
62 for _, file := range files {
63 if err := editor.OpenFile(ctx, file); err != nil {
64 t.Fatal(err)
65 }
66 }
67 ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
68 defer cancel()
69
70 i := 1
71 // MagicNumber is an identifier that occurs in roaring.go. Just change it
72 // arbitrarily.
73 if err := editor.RegexpReplace(ctx, "roaring/roaring.go", "MagicNumber", fmt.Sprintf("MagicNumber%d", 1)); err != nil {
74 t.Fatal(err)
75 }
76 for {
77 select {
78 case <-ctx.Done():
79 return
80 default:
81 }
82 if err := editor.RegexpReplace(ctx, "roaring/roaring.go", fmt.Sprintf("MagicNumber%d", i), fmt.Sprintf("MagicNumber%d", i+1)); err != nil {
83 t.Fatal(err)
84 }
85 // Simulate (very fast) typing.
86 //
87 // Typing 80 wpm ~150ms per keystroke.
88 time.Sleep(150 * time.Millisecond)
89 i++
90 }
91 }