| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
|
| 72 |
|
| 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 |
|
| 86 |
|
| 87 |
|
| 88 |
time.Sleep(150 * time.Millisecond) |
| 89 |
i++ |
| 90 |
} |
| 91 |
} |