test: separate LSP initialization and shutdown timeouts
Test / Build skipped: 15, passed: 805
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good

This commit is contained in:
2026-09-29 16:33:36 +01:00
parent 73aaeb0832
commit 3f675ca0c9
@@ -8,6 +8,8 @@ import java.net.Socket;
import static org.junit.jupiter.api.Assertions.*;
class LspServerLifecycleTest {
private static final int INITIALIZATION_TIMEOUT_MS = 10_000;
private static final int SHUTDOWN_TIMEOUT_MS = 2_000;
@TempDir Path temporary;
@Test void projectEndpointsAreIndependentAndShutdownClosesConnectedSockets() throws Exception {
@@ -21,12 +23,15 @@ class LspServerLifecycleTest {
assertNotEquals(endpoint.port(), lifecycle.endpoint(second).orElseThrow().port());
assertTrue(lifecycle.endpoint(new LspProjectContext("first", "other-language", temporary)).isEmpty());
try (var socket = new Socket(endpoint.host(), endpoint.port())) {
socket.setSoTimeout(2000);
// Cold LSP/compiler initialization can be slower on a loaded CI worker.
// Keep its budget separate from the socket-closure assertion below.
socket.setSoTimeout(INITIALIZATION_TIMEOUT_MS);
String request = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"rootUri\":\"" + temporary.toUri() + "\",\"capabilities\":{}}}";
byte[] body = request.getBytes(java.nio.charset.StandardCharsets.UTF_8);
socket.getOutputStream().write(("Content-Length: " + body.length + "\r\n\r\n").getBytes(java.nio.charset.StandardCharsets.US_ASCII));
socket.getOutputStream().write(body); socket.getOutputStream().flush();
assertNotEquals(-1, socket.getInputStream().read());
socket.setSoTimeout(SHUTDOWN_TIMEOUT_MS);
lifecycle.shutdownServer(first);
socket.getInputStream().readAllBytes(); // Buffered reply drains, then EOF; no abandoned client connection.
assertTrue(lifecycle.endpoint(first).isEmpty());