Skip to content

Commit 03c5b8d

Browse files
committed
Fix elicitation and resource subscription tests that deadlock on a single CPU (#854)
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
1 parent 5b9c2fb commit 03c5b8d

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

mcp-test/src/main/java/io/modelcontextprotocol/AbstractMcpClientServerIntegrationTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.junit.jupiter.params.provider.MethodSource;
5454
import org.junit.jupiter.params.provider.ValueSource;
5555
import reactor.core.publisher.Mono;
56-
import reactor.test.StepVerifier;
5756

5857
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
5958
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
@@ -404,6 +403,8 @@ void testCreateElicitationSuccess(String clientType) {
404403
.addContent(new McpSchema.TextContent("CALL RESPONSE"))
405404
.build();
406405

406+
AtomicReference<McpSchema.ElicitResult> elicitResultRef = new AtomicReference<>();
407+
407408
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
408409
.tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build())
409410
.callHandler((exchange, request) -> {
@@ -414,13 +415,9 @@ void testCreateElicitationSuccess(String clientType) {
414415
Map.of("type", "object", "properties", Map.of("message", Map.of("type", "string"))))
415416
.build();
416417

417-
StepVerifier.create(exchange.createElicitation(elicitationRequest)).consumeNextWith(result -> {
418-
assertThat(result).isNotNull();
419-
assertThat(result.action()).isEqualTo(McpSchema.ElicitResult.Action.ACCEPT);
420-
assertThat(result.content().get("message")).isEqualTo("Test message");
421-
}).verifyComplete();
422-
423-
return Mono.just(callResponse);
418+
return exchange.createElicitation(elicitationRequest)
419+
.doOnNext(elicitResultRef::set)
420+
.thenReturn(callResponse);
424421
})
425422
.build();
426423

@@ -438,6 +435,11 @@ void testCreateElicitationSuccess(String clientType) {
438435

439436
assertThat(response).isNotNull();
440437
assertThat(response).isEqualTo(callResponse);
438+
assertWith(elicitResultRef.get(), result -> {
439+
assertThat(result).isNotNull();
440+
assertThat(result.action()).isEqualTo(McpSchema.ElicitResult.Action.ACCEPT);
441+
assertThat(result.content().get("message")).isEqualTo("Test message");
442+
});
441443
}
442444
finally {
443445
mcpServer.closeGracefully().block();

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -610,22 +610,17 @@ void testListAllResourceTemplatesReturnsImmutableList() {
610610
});
611611
}
612612

613-
// @Test
613+
@Test
614614
void testResourceSubscription() {
615615
withClient(createMcpTransport(), mcpAsyncClient -> {
616-
StepVerifier.create(mcpAsyncClient.listResources()).consumeNextWith(resources -> {
617-
if (!resources.resources().isEmpty()) {
618-
Resource firstResource = resources.resources().get(0);
619-
620-
// Test subscribe
621-
StepVerifier.create(mcpAsyncClient.subscribeResource(new SubscribeRequest(firstResource.uri())))
622-
.verifyComplete();
623-
624-
// Test unsubscribe
625-
StepVerifier.create(mcpAsyncClient.unsubscribeResource(new UnsubscribeRequest(firstResource.uri())))
626-
.verifyComplete();
616+
StepVerifier.create(mcpAsyncClient.listResources().flatMap(resources -> {
617+
if (resources.resources().isEmpty()) {
618+
return Mono.empty();
627619
}
628-
}).verifyComplete();
620+
Resource firstResource = resources.resources().get(0);
621+
return mcpAsyncClient.subscribeResource(new SubscribeRequest(firstResource.uri()))
622+
.then(mcpAsyncClient.unsubscribeResource(new UnsubscribeRequest(firstResource.uri())));
623+
})).verifyComplete();
629624
});
630625
}
631626

0 commit comments

Comments
 (0)