Fix elicitation and resource subscription tests that deadlock on a single CPU (#854)

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
This commit is contained in:
Dariusz Jędrzejczyk 2026-03-05 09:53:37 +01:00 • committed by GitHub
commit 6e4ce1c1a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 21 deletions

View file

@ -53,7 +53,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
@ -404,6 +403,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
.addContent(new McpSchema.TextContent("CALL RESPONSE"))
.build();
AtomicReference<McpSchema.ElicitResult> elicitResultRef = new AtomicReference<>();
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
.tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build())
.callHandler((exchange, request) -> {
@ -414,13 +415,9 @@ public abstract class AbstractMcpClientServerIntegrationTests {
Map.of("type", "object", "properties", Map.of("message", Map.of("type", "string"))))
.build();
StepVerifier.create(exchange.createElicitation(elicitationRequest)).consumeNextWith(result -> {
assertThat(result).isNotNull();
assertThat(result.action()).isEqualTo(McpSchema.ElicitResult.Action.ACCEPT);
assertThat(result.content().get("message")).isEqualTo("Test message");
}).verifyComplete();
return Mono.just(callResponse);
return exchange.createElicitation(elicitationRequest)
.doOnNext(elicitResultRef::set)
.thenReturn(callResponse);
})
.build();
@ -438,6 +435,11 @@ public abstract class AbstractMcpClientServerIntegrationTests {
assertThat(response).isNotNull();
assertThat(response).isEqualTo(callResponse);
assertWith(elicitResultRef.get(), result -> {
assertThat(result).isNotNull();
assertThat(result.action()).isEqualTo(McpSchema.ElicitResult.Action.ACCEPT);
assertThat(result.content().get("message")).isEqualTo("Test message");
});
}
finally {
mcpServer.closeGracefully().block();

View file

@ -610,22 +610,17 @@ public abstract class AbstractMcpAsyncClientTests {
});
}
// @Test
@Test
void testResourceSubscription() {
withClient(createMcpTransport(), mcpAsyncClient -> {
StepVerifier.create(mcpAsyncClient.listResources()).consumeNextWith(resources -> {
if (!resources.resources().isEmpty()) {
Resource firstResource = resources.resources().get(0);
// Test subscribe
StepVerifier.create(mcpAsyncClient.subscribeResource(new SubscribeRequest(firstResource.uri())))
.verifyComplete();
// Test unsubscribe
StepVerifier.create(mcpAsyncClient.unsubscribeResource(new UnsubscribeRequest(firstResource.uri())))
.verifyComplete();
StepVerifier.create(mcpAsyncClient.listResources().flatMap(resources -> {
if (resources.resources().isEmpty()) {
return Mono.empty();
}
}).verifyComplete();
Resource firstResource = resources.resources().get(0);
return mcpAsyncClient.subscribeResource(new SubscribeRequest(firstResource.uri()))
.then(mcpAsyncClient.unsubscribeResource(new UnsubscribeRequest(firstResource.uri())));
})).verifyComplete();
});
}