Debian Codegraph @

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

raw symbols SCIP
1 // Copyright 2024 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 "sync"
9 "testing"
10
11 "golang.org/x/tools/gopls/internal/protocol"
12 . "golang.org/x/tools/gopls/internal/test/integration"
13 "golang.org/x/tools/gopls/internal/test/integration/fake"
14 )
15
16 // BenchmarkDiagnosePackageFiles measures how long it takes to request
17 // diagnostics for 10 files in a single package, following a change to that
18 // package.
19 //
20 // This can be used to measure the efficiency of pull diagnostics
21 // (golang/go#53275).
22 func BenchmarkDiagnosePackageFiles(b *testing.B) {
23 if testing.Short() {
24 b.Skip("pull diagnostics are not supported by the benchmark dashboard baseline")
25 }
26
27 env := getRepo(b, "kubernetes").newEnv(b, fake.EditorConfig{
28 Settings: map[string]any{
29 "pullDiagnostics": true, // currently required for pull diagnostic support
30 },
31 }, "diagnosePackageFiles", false)
32
33 // 10 arbitrary files in a single package.
34 files := []string{
35 "pkg/kubelet/active_deadline.go", // 98 lines
36 "pkg/kubelet/active_deadline_test.go", // 95 lines
37 "pkg/kubelet/kubelet.go", // 2439 lines
38 "pkg/kubelet/kubelet_pods.go", // 2061 lines
39 "pkg/kubelet/kubelet_network.go", // 70 lines
40 "pkg/kubelet/kubelet_network_test.go", // 46 lines
41 "pkg/kubelet/pod_workers.go", // 1323 lines
42 "pkg/kubelet/pod_workers_test.go", // 1758 lines
43 "pkg/kubelet/runonce.go", // 175 lines
44 "pkg/kubelet/volume_host.go", // 297 lines
45 }
46
47 env.Await(InitialWorkspaceLoad)
48
49 for _, file := range files {
50 env.OpenFile(file)
51 }
52
53 env.AfterChange()
54
55 edit := makeEditFunc(env, files[0])
56
57 if stopAndRecord := startProfileIfSupported(b, env, qualifiedName("kubernetes", "diagnosePackageFiles")); stopAndRecord != nil {
58 defer stopAndRecord()
59 }
60
61 for b.Loop() {
62 edit()
63 var wg sync.WaitGroup
64 for _, file := range files {
65 wg.Go(func() {
66 fileDiags := env.Diagnostics(file)
67 for _, d := range fileDiags {
68 if d.Severity == protocol.SeverityError {
69 b.Errorf("unexpected error diagnostic: %s", d.Message)
70 }
71 }
72 })
73 }
74 wg.Wait()
75 }
76 }