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:
parent
5b9c2fb414
commit
03c5b8d0ec
2 changed files with 18 additions and 21 deletions
|
|
@ -53,7 +53,6 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.test.StepVerifier;
|
|
||||||
|
|
||||||
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
|
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
|
||||||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
|
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
|
||||||
|
|
@ -404,6 +403,8 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
.addContent(new McpSchema.TextContent("CALL RESPONSE"))
|
.addContent(new McpSchema.TextContent("CALL RESPONSE"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
AtomicReference<McpSchema.ElicitResult> elicitResultRef = new AtomicReference<>();
|
||||||
|
|
||||||
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
|
||||||
.tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build())
|
.tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build())
|
||||||
.callHandler((exchange, request) -> {
|
.callHandler((exchange, request) -> {
|
||||||
|
|
@ -414,13 +415,9 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
Map.of("type", "object", "properties", Map.of("message", Map.of("type", "string"))))
|
Map.of("type", "object", "properties", Map.of("message", Map.of("type", "string"))))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
StepVerifier.create(exchange.createElicitation(elicitationRequest)).consumeNextWith(result -> {
|
return exchange.createElicitation(elicitationRequest)
|
||||||
assertThat(result).isNotNull();
|
.doOnNext(elicitResultRef::set)
|
||||||
assertThat(result.action()).isEqualTo(McpSchema.ElicitResult.Action.ACCEPT);
|
.thenReturn(callResponse);
|
||||||
assertThat(result.content().get("message")).isEqualTo("Test message");
|
|
||||||
}).verifyComplete();
|
|
||||||
|
|
||||||
return Mono.just(callResponse);
|
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -438,6 +435,11 @@ public abstract class AbstractMcpClientServerIntegrationTests {
|
||||||
|
|
||||||
assertThat(response).isNotNull();
|
assertThat(response).isNotNull();
|
||||||
assertThat(response).isEqualTo(callResponse);
|
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 {
|
finally {
|
||||||
mcpServer.closeGracefully().block();
|
mcpServer.closeGracefully().block();
|
||||||
|
|
|
||||||
|
|
@ -610,22 +610,17 @@ public abstract class AbstractMcpAsyncClientTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
void testResourceSubscription() {
|
void testResourceSubscription() {
|
||||||
withClient(createMcpTransport(), mcpAsyncClient -> {
|
withClient(createMcpTransport(), mcpAsyncClient -> {
|
||||||
StepVerifier.create(mcpAsyncClient.listResources()).consumeNextWith(resources -> {
|
StepVerifier.create(mcpAsyncClient.listResources().flatMap(resources -> {
|
||||||
if (!resources.resources().isEmpty()) {
|
if (resources.resources().isEmpty()) {
|
||||||
Resource firstResource = resources.resources().get(0);
|
return Mono.empty();
|
||||||
|
|
||||||
// Test subscribe
|
|
||||||
StepVerifier.create(mcpAsyncClient.subscribeResource(new SubscribeRequest(firstResource.uri())))
|
|
||||||
.verifyComplete();
|
|
||||||
|
|
||||||
// Test unsubscribe
|
|
||||||
StepVerifier.create(mcpAsyncClient.unsubscribeResource(new UnsubscribeRequest(firstResource.uri())))
|
|
||||||
.verifyComplete();
|
|
||||||
}
|
}
|
||||||
}).verifyComplete();
|
Resource firstResource = resources.resources().get(0);
|
||||||
|
return mcpAsyncClient.subscribeResource(new SubscribeRequest(firstResource.uri()))
|
||||||
|
.then(mcpAsyncClient.unsubscribeResource(new UnsubscribeRequest(firstResource.uri())));
|
||||||
|
})).verifyComplete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue