1
0
mirror of https://github.com/golang/go synced 2024-10-01 04:08:32 -06:00
go/internal/lsp/regtest/shared_test.go
Rob Findley afe1c6fc1b internal/lsp/regtest: remove calls to t.Parallel()
Originally I decided to use t.Parallel() in hopes of uncovering new
bugs. That may have worked... but manifested as rare flakes that are
difficult to diagnose (golang.org/issues/37318).

Since this level of parallelism is extremely unlikely in normal gopls
workloads, I'm going to remove the t.Parallel() calls in hopes of
eliminating this flakiness. I'd rather be able to continue running these
tests.

Also, don't run in the 'Shared' execution mode by default: normal gopls
execution is either as a sidecar (the Singleton execution mode), or as a
daemon (the Forwarded execution mode).

Un-skip the TestGoToStdlibDefinition test, as hopefully it will no
longer flake.

Updates golang/go#37318.

Change-Id: Id73ee3c8702ab4ab1d039baa038fbce879e38df8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221379
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-27 18:46:34 +00:00

66 lines
1.8 KiB
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package regtest
import (
"context"
"testing"
"golang.org/x/tools/internal/lsp/fake"
)
const sharedProgram = `
-- go.mod --
module mod
go 1.12
-- main.go --
package main
import "fmt"
func main() {
fmt.Println("Hello World.")
}`
func runShared(t *testing.T, program string, testFunc func(ctx context.Context, t *testing.T, env1 *Env, env2 *Env)) {
// Only run these tests in forwarded modes.
modes := runner.Modes() & (Forwarded | SeparateProcess)
runner.RunInMode(modes, t, sharedProgram, func(ctx context.Context, t *testing.T, env1 *Env) {
// Create a second test session connected to the same workspace and server
// as the first.
env2 := NewEnv(ctx, t, env1.W, env1.Server)
testFunc(ctx, t, env1, env2)
})
}
func TestSimultaneousEdits(t *testing.T) {
runShared(t, exampleProgram, func(ctx context.Context, t *testing.T, env1 *Env, env2 *Env) {
// In editor #1, break fmt.Println as before.
edit1 := fake.NewEdit(5, 11, 5, 12, "")
env1.OpenFile("main.go")
env1.EditBuffer("main.go", edit1)
// In editor #2 remove the closing brace.
edit2 := fake.NewEdit(6, 0, 6, 1, "")
env2.OpenFile("main.go")
env2.EditBuffer("main.go", edit2)
// Now check that we got different diagnostics in each environment.
env1.Await(DiagnosticAt("main.go", 5, 5))
env2.Await(DiagnosticAt("main.go", 7, 0))
})
}
func TestShutdown(t *testing.T) {
runShared(t, sharedProgram, func(ctx context.Context, t *testing.T, env1 *Env, env2 *Env) {
env1.CloseEditor()
// Now make an edit in editor #2 to trigger diagnostics.
edit2 := fake.NewEdit(6, 0, 6, 1, "")
env2.OpenFile("main.go")
env2.EditBuffer("main.go", edit2)
env2.Await(DiagnosticAt("main.go", 7, 0))
})
}