internal/lsp: allow command line tests to connect through a pipe

With this change (finally, after a lot of detours) if you run the lsp tests with `-race -pipe` then you
can reliably reproduce the race in golang/go#30091

Change-Id: Ibd9fda5e07409a15d1bc8d14cb46fde41155aa6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/169999
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Ian Cottrell 2019-03-28 17:17:40 -04:00
parent ab21143f23
commit 4471d52094
3 changed files with 17 additions and 4 deletions

View File

@ -40,7 +40,11 @@ func (l diagnostics) test(t *testing.T, e *packagestest.Exported) {
if len(want) == 1 && want[0].Message == "" { if len(want) == 1 && want[0].Message == "" {
continue continue
} }
args := []string{"check", fname} args := []string{}
if *internalPipe {
args = append(args, "-remote=internal")
}
args = append(args, "check", fname)
app := &cmd.Application{} app := &cmd.Application{}
app.Config = *e.Config app.Config = *e.Config
out := captureStdOut(t, func() { out := captureStdOut(t, func() {

View File

@ -119,7 +119,15 @@ func (app *Application) commands() []tool.Application {
func (app *Application) connect(ctx context.Context, client protocol.Client) (protocol.Server, error) { func (app *Application) connect(ctx context.Context, client protocol.Client) (protocol.Server, error) {
var server protocol.Server var server protocol.Server
if app.Remote != "" { switch app.Remote {
case "":
server = lsp.NewServer(client)
case "internal":
cr, sw, _ := os.Pipe()
sr, cw, _ := os.Pipe()
_, server = protocol.RunClient(ctx, jsonrpc2.NewHeaderStream(cr, cw), client)
go lsp.RunServer(ctx, jsonrpc2.NewHeaderStream(sr, sw))
default:
conn, err := net.Dial("tcp", app.Remote) conn, err := net.Dial("tcp", app.Remote)
if err != nil { if err != nil {
return nil, err return nil, err
@ -129,8 +137,6 @@ func (app *Application) connect(ctx context.Context, client protocol.Client) (pr
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else {
server = lsp.NewServer(client)
} }
params := &protocol.InitializeParams{} params := &protocol.InitializeParams{}
params.RootURI = string(span.FileURI(app.Config.Dir)) params.RootURI = string(span.FileURI(app.Config.Dir))

View File

@ -5,6 +5,7 @@
package cmd_test package cmd_test
import ( import (
"flag"
"io/ioutil" "io/ioutil"
"os" "os"
"strings" "strings"
@ -23,6 +24,8 @@ const (
expectedFormatCount = 4 expectedFormatCount = 4
) )
var internalPipe = flag.Bool("pipe", false, "connect the command line client to a server through a pipe")
func TestCommandLine(t *testing.T) { func TestCommandLine(t *testing.T) {
packagestest.TestAll(t, testCommandLine) packagestest.TestAll(t, testCommandLine)
} }