Fix non-OK HTTP POST responses handling (#374)
Currently, JDK HttpClient SSE implementation incorrectly handles a non-2xx HTTP response code for POST. Instead of immediately failing the caller, it ignores the issue and the user awaits until the timeout kicks in. Set HttpClient to use HTTP/1.1 version explicitly for tests A related problem happened with the WebClient Streamable HTTP implementation, where the error was swallowed for non-400 responses. Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
This commit is contained in:
parent
b37c32cdba
commit
95df67ec05
1 changed files with 42 additions and 6 deletions
|
|
@ -32,6 +32,7 @@ import org.junit.jupiter.api.AfterEach;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -96,9 +97,11 @@ class WebMvcSseIntegrationTests {
|
|||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
reactor.netty.http.HttpResources.disposeLoopsAndConnections();
|
||||
if (mcpServerTransportProvider != null) {
|
||||
mcpServerTransportProvider.closeGracefully().block();
|
||||
}
|
||||
Schedulers.shutdownNow();
|
||||
if (tomcatServer.appContext() != null) {
|
||||
tomcatServer.appContext().close();
|
||||
}
|
||||
|
|
@ -779,6 +782,33 @@ class WebMvcSseIntegrationTests {
|
|||
mcpServer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThrowingToolCallIsCaughtBeforeTimeout() {
|
||||
McpSyncServer mcpServer = McpServer.sync(mcpServerTransportProvider)
|
||||
.capabilities(ServerCapabilities.builder().tools(true).build())
|
||||
.tools(new McpServerFeatures.SyncToolSpecification(
|
||||
new McpSchema.Tool("tool1", "tool1 description", emptyJsonSchema), (exchange, request) -> {
|
||||
// We trigger a timeout on blocking read, raising an exception
|
||||
Mono.never().block(Duration.ofSeconds(1));
|
||||
return null;
|
||||
}))
|
||||
.build();
|
||||
|
||||
try (var mcpClient = clientBuilder.requestTimeout(Duration.ofMillis(6666)).build()) {
|
||||
InitializeResult initResult = mcpClient.initialize();
|
||||
assertThat(initResult).isNotNull();
|
||||
|
||||
// We expect the tool call to fail immediately with the exception raised by
|
||||
// the offending tool
|
||||
// instead of getting back a timeout.
|
||||
assertThatExceptionOfType(McpError.class)
|
||||
.isThrownBy(() -> mcpClient.callTool(new McpSchema.CallToolRequest("tool1", Map.of())))
|
||||
.withMessageContaining("Timeout on blocking read");
|
||||
}
|
||||
|
||||
mcpServer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToolListChangeHandlingSuccess() {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue