|
13 | 13 | import java.io.InputStreamReader; |
14 | 14 | import java.io.OutputStream; |
15 | 15 | import java.io.PrintStream; |
| 16 | +import java.lang.reflect.Field; |
16 | 17 | import java.nio.charset.StandardCharsets; |
17 | 18 | import java.time.Duration; |
18 | 19 | import java.util.Map; |
|
30 | 31 | import org.junit.jupiter.api.Test; |
31 | 32 | import reactor.core.publisher.Flux; |
32 | 33 | import reactor.core.publisher.Mono; |
| 34 | +import reactor.core.publisher.Sinks; |
33 | 35 | import reactor.core.scheduler.Schedulers; |
34 | 36 | import reactor.test.StepVerifier; |
35 | 37 |
|
@@ -307,6 +309,34 @@ void shouldHandleSessionClose() { |
307 | 309 | verify(mockSession).closeGracefully(); |
308 | 310 | } |
309 | 311 |
|
| 312 | + @Test |
| 313 | + @SuppressWarnings("unchecked") |
| 314 | + void sendMessageWaitsForBothInboundAndOutboundReadinessSignals() throws Exception { |
| 315 | + transportProvider = new StdioServerTransportProvider(McpJsonDefaults.getMapper(), System.in, |
| 316 | + testOutPrintStream); |
| 317 | + Class<?> transportClass = Class |
| 318 | + .forName(StdioServerTransportProvider.class.getName() + "$StdioMcpSessionTransport"); |
| 319 | + var constructor = transportClass.getDeclaredConstructor(StdioServerTransportProvider.class); |
| 320 | + constructor.setAccessible(true); |
| 321 | + McpServerTransport transport = (McpServerTransport) constructor.newInstance(transportProvider); |
| 322 | + |
| 323 | + Field inboundReadyField = StdioServerTransportProvider.class.getDeclaredField("inboundReady"); |
| 324 | + inboundReadyField.setAccessible(true); |
| 325 | + Sinks.One<Void> inboundReady = (Sinks.One<Void>) inboundReadyField.get(transportProvider); |
| 326 | + |
| 327 | + Field outboundReadyField = transportClass.getDeclaredField("outboundReady"); |
| 328 | + outboundReadyField.setAccessible(true); |
| 329 | + Sinks.One<Void> outboundReady = (Sinks.One<Void>) outboundReadyField.get(transport); |
| 330 | + |
| 331 | + StepVerifier |
| 332 | + .create(transport.sendMessage( |
| 333 | + new McpSchema.JSONRPCNotification(McpSchema.JSONRPC_VERSION, "test/notification", Map.of()))) |
| 334 | + .then(() -> inboundReady.tryEmitValue(null)) |
| 335 | + .expectNoEvent(Duration.ofMillis(100)) |
| 336 | + .then(() -> outboundReady.tryEmitValue(null)) |
| 337 | + .verifyComplete(); |
| 338 | + } |
| 339 | + |
310 | 340 | @Test |
311 | 341 | void shouldHandleConcurrentSendMessage() throws Exception { |
312 | 342 | int messageCount = 500; |
|
0 commit comments