Skip to content

Commit 2c5cc80

Browse files
committed
test: fix race conditions and re-enable disabled tests
- Re-enable previously disabled `testSessionClose()` tests in resiliency test suites - Remove unused `@Disabled` import from WebClientStreamableHttpTransportErrorHandlingTest - Fix race condition in async client tests by not advertising roots capability during initialization - Prevents server from listing roots during init which could cause timing issues when disconnecting immediately after initialization - Applied fix to AbstractMcpAsyncClientResiliencyTests (both mcp and mcp-test modules) and HttpSseMcpAsyncClientLostConnectionTests Signed-off-by: Christian Tzolov <[email protected]>
1 parent a704dd9 commit 2c5cc80

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransportErrorHandlingTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.junit.jupiter.api.AfterEach;
2222
import org.junit.jupiter.api.BeforeEach;
23-
import org.junit.jupiter.api.Disabled;
2423
import org.junit.jupiter.api.Test;
2524
import org.junit.jupiter.api.Timeout;
2625
import org.springframework.web.reactive.function.client.WebClient;

mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,13 @@ McpAsyncClient client(McpClientTransport transport, Function<McpClient.AsyncSpec
135135
AtomicReference<McpAsyncClient> client = new AtomicReference<>();
136136

137137
assertThatCode(() -> {
138+
// Do not advertise roots. Otherwise, the server will list roots during
139+
// initialization. The client responds asynchronously, and there might be a
140+
// rest condition in tests where we disconnect right after initialization.
138141
McpClient.AsyncSpec builder = McpClient.async(transport)
139142
.requestTimeout(getRequestTimeout())
140143
.initializationTimeout(getInitializationTimeout())
141-
.capabilities(McpSchema.ClientCapabilities.builder().roots(true).build());
144+
.capabilities(McpSchema.ClientCapabilities.builder().build());
142145
builder = customizer.apply(builder);
143146
client.set(builder.build());
144147
}).doesNotThrowAnyException();
@@ -212,7 +215,6 @@ void testCallTool() {
212215
}
213216

214217
@Test
215-
@Disabled("Temporarily disabled")
216218
void testSessionClose() {
217219
withClient(createMcpTransport(), mcpAsyncClient -> {
218220
StepVerifier.create(mcpAsyncClient.initialize()).expectNextCount(1).verifyComplete();

mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientResiliencyTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ McpAsyncClient client(McpClientTransport transport, Function<McpClient.AsyncSpec
136136
AtomicReference<McpAsyncClient> client = new AtomicReference<>();
137137

138138
assertThatCode(() -> {
139+
// Do not advertise roots. Otherwise, the server will list roots during
140+
// initialization. The client responds asynchronously, and there might be a
141+
// rest condition in tests where we disconnect right after initialization.
139142
McpClient.AsyncSpec builder = McpClient.async(transport)
140143
.requestTimeout(getRequestTimeout())
141144
.initializationTimeout(getInitializationTimeout())
142-
.capabilities(McpSchema.ClientCapabilities.builder().roots(true).build());
145+
.capabilities(McpSchema.ClientCapabilities.builder().build());
143146
builder = customizer.apply(builder);
144147
client.set(builder.build());
145148
}).doesNotThrowAnyException();
@@ -213,7 +216,6 @@ void testCallTool() {
213216
}
214217

215218
@Test
216-
@Disabled("Temporarily disabled")
217219
void testSessionClose() {
218220
withClient(createMcpTransport(), mcpAsyncClient -> {
219221
StepVerifier.create(mcpAsyncClient.initialize()).expectNextCount(1).verifyComplete();

mcp/src/test/java/io/modelcontextprotocol/client/HttpSseMcpAsyncClientLostConnectionTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ McpAsyncClient client(McpClientTransport transport) {
9898
AtomicReference<McpAsyncClient> client = new AtomicReference<>();
9999

100100
assertThatCode(() -> {
101+
// Do not advertise roots. Otherwise, the server will list roots during
102+
// initialization. The client responds asynchronously, and there might be a
103+
// rest condition in tests where we disconnect right after initialization.
101104
McpClient.AsyncSpec builder = McpClient.async(transport)
102105
.requestTimeout(Duration.ofSeconds(14))
103106
.initializationTimeout(Duration.ofSeconds(2))

0 commit comments

Comments
 (0)