Skip to content

Commit

Permalink
lsp: Increase test buffered channel size (#657)
Browse files Browse the repository at this point in the history
TestLanguageServerMultipleFiles is sometimes locking up as the handler
can't save new messages as the channel is waiting to be read and the
part of the test that is waiting to read those particular messages is
later and waiting for another file first.

This makes the buffered channels larger to allow more messages to be
received for each file so that we can no block and check the messages we
want in order as before.

Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 authored Apr 17, 2024
1 parent 63148df commit 8c9b76b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/lsp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const mainRegoFileName = "/main.rego"

const defaultTimeout = 3 * time.Second

const defaultBufferedChannelSize = 5

// InMemoryReadWriteCloser is an in-memory implementation of jsonrpc2.ReadWriteCloser.
type InMemoryReadWriteCloser struct {
Buffer bytes.Buffer
Expand Down Expand Up @@ -87,7 +89,7 @@ allow = true
go ls.StartDiagnosticsWorker(ctx)
go ls.StartConfigWorker(ctx)

receivedMessages := make(chan FileDiagnostics, 1)
receivedMessages := make(chan FileDiagnostics, defaultBufferedChannelSize)
clientHandler := func(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Method == methodTextDocumentPublishDiagnostics {
var requestData FileDiagnostics
Expand Down Expand Up @@ -331,9 +333,9 @@ ignore:
go ls.StartDiagnosticsWorker(ctx)
go ls.StartConfigWorker(ctx)

authzFileMessages := make(chan FileDiagnostics, 1)
adminsFileMessages := make(chan FileDiagnostics, 1)
ignoredFileMessages := make(chan FileDiagnostics, 1)
authzFileMessages := make(chan FileDiagnostics, defaultBufferedChannelSize)
adminsFileMessages := make(chan FileDiagnostics, defaultBufferedChannelSize)
ignoredFileMessages := make(chan FileDiagnostics, defaultBufferedChannelSize)
clientHandler := func(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Method == "textDocument/publishDiagnostics" {
var requestData FileDiagnostics
Expand Down Expand Up @@ -562,7 +564,7 @@ allow := true
go ls.StartDiagnosticsWorker(ctx)
go ls.StartConfigWorker(ctx)

receivedMessages := make(chan FileDiagnostics, 1)
receivedMessages := make(chan FileDiagnostics, defaultBufferedChannelSize)
clientHandler := func(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Method == methodTextDocumentPublishDiagnostics {
var requestData FileDiagnostics
Expand Down

0 comments on commit 8c9b76b

Please sign in to comment.