Debian Codegraph @

gopls/internal/test/integration/web/flight_test.go

raw symbols SCIP
1 // Copyright 2025 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 web_test
6
7 import (
8 "encoding/json"
9 "runtime"
10 "testing"
11
12 "golang.org/x/tools/gopls/internal/debug"
13 "golang.org/x/tools/gopls/internal/protocol"
14 "golang.org/x/tools/gopls/internal/protocol/command"
15 . "golang.org/x/tools/gopls/internal/test/integration"
16 )
17
18 // TestFlightRecorder checks that the flight recorder is minimally functional.
19 func TestFlightRecorder(t *testing.T) {
20 // The usual UNIX mechanisms cause timely termination of the
21 // cmd/trace process, but this doesn't happen on Windows,
22 // leading to CI failures because of process->file locking.
23 // Rather than invent a complex mechanism, skip the test:
24 // this feature is only for gopls developers anyway.
25 // Better long term solutions are CL 677262 and issue #66843.
26 if runtime.GOOS == "windows" {
27 t.Skip("not reliable on windows")
28 }
29
30 // This is a global hammer; it won't play nicely with
31 // multiple concurrent tests of Flight Recorder.
32 t.Cleanup(debug.KillTraceViewers)
33
34 const files = `
35 -- go.mod --
36 module example.com
37
38 -- a/a.go --
39 package a
40
41 const A = 1
42 `
43
44 Run(t, files, func(t *testing.T, env *Env) {
45 env.OpenFile("a/a.go")
46
47 // Start the debug server.
48 var result command.DebuggingResult
49 env.ExecuteCommand(&protocol.ExecuteCommandParams{
50 Command: command.StartDebugging.String(),
51 Arguments: []json.RawMessage{json.RawMessage("{}")}, // no args -> pick port
52 }, &result)
53 uri := result.URLs[0]
54 t.Logf("StartDebugging: URLs[0] = %s", uri)
55
56 // Check the debug server page is sensible.
57 doc1 := get(t, uri)
58 checkMatch(t, true, doc1, "Gopls server information")
59 checkMatch(t, true, doc1, `<a href="/flightrecorder">Flight recorder</a>`)
60
61 // "Click" the Flight Recorder link.
62 // It should redirect to the web server
63 // of a "go tool trace" process.
64 // The resulting web page is entirely programmatic,
65 // so we check for an arbitrary expected symbol.
66 doc2 := get(t, uri+"/flightrecorder")
67 checkMatch(t, true, doc2, `onTraceViewerImportFail`)
68 })
69 }