summaryrefslogtreecommitdiff
path: root/internal/lsp/init_shutdown_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-02 14:05:16 +0200
committerPaul Buetow <paul@buetow.org>2026-03-02 14:05:16 +0200
commit8fa31daeba7a6617f08027a5f9f68bb612587772 (patch)
tree25979d0c922eff767ef33e14091d66bb8fcee20a /internal/lsp/init_shutdown_test.go
parent4649658bd71c4754dc5dde2fb5e1f4de2fe269d4 (diff)
lsp: cancel handler contexts on shutdown via server context (task 423)
Diffstat (limited to 'internal/lsp/init_shutdown_test.go')
-rw-r--r--internal/lsp/init_shutdown_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/lsp/init_shutdown_test.go b/internal/lsp/init_shutdown_test.go
index 2847170..4e1bd2f 100644
--- a/internal/lsp/init_shutdown_test.go
+++ b/internal/lsp/init_shutdown_test.go
@@ -2,10 +2,13 @@ package lsp
import (
"bytes"
+ "context"
"encoding/json"
+ "errors"
"io"
"log"
"testing"
+ "time"
)
func TestHandleShutdown_Replies(t *testing.T) {
@@ -20,3 +23,41 @@ func TestHandleShutdown_Replies(t *testing.T) {
t.Fatalf("unexpected shutdown response: %+v", resp)
}
}
+
+func TestHandleShutdown_CancelsServerContext(t *testing.T) {
+ var out bytes.Buffer
+ s := NewServer(bytes.NewReader(nil), &out, log.New(io.Discard, "", 0), ServerOptions{})
+ req := Request{JSONRPC: "2.0", ID: json.RawMessage("12"), Method: "shutdown"}
+ s.handleShutdown(req)
+
+ ctx, cancel := s.requestTimeoutContext(2 * time.Second)
+ defer cancel()
+ select {
+ case <-ctx.Done():
+ if !errors.Is(ctx.Err(), context.Canceled) {
+ t.Fatalf("expected canceled context, got %v", ctx.Err())
+ }
+ default:
+ t.Fatalf("expected canceled context after shutdown")
+ }
+}
+
+func TestHandleExit_CancelsServerContext(t *testing.T) {
+ var out bytes.Buffer
+ s := NewServer(bytes.NewReader(nil), &out, log.New(io.Discard, "", 0), ServerOptions{})
+ s.handleExit()
+ if !s.exited.Load() {
+ t.Fatalf("expected exited flag to be set")
+ }
+
+ ctx, cancel := s.requestTimeoutContext(2 * time.Second)
+ defer cancel()
+ select {
+ case <-ctx.Done():
+ if !errors.Is(ctx.Err(), context.Canceled) {
+ t.Fatalf("expected canceled context, got %v", ctx.Err())
+ }
+ default:
+ t.Fatalf("expected canceled context after exit")
+ }
+}