Skip to content

Commit 850376e

Browse files
committed
test(mcp-test): await async GET stream in version-negotiation assertions
The GET /mcp stream is opened asynchronously once initialize creates the session, so asserting recorded calls immediately races under load (seen as Jackson 2 Integration Tests failing usesLatestVersion with Expected size: 3 but was: 2). Await the recorded GET before asserting header propagation.
1 parent 50b67c2 commit 850376e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎mcp-test/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.modelcontextprotocol.common;
66

7+
import java.time.Duration;
78
import java.util.List;
89
import java.util.Map;
910
import java.util.Objects;
@@ -32,6 +33,7 @@
3233
import static org.assertj.core.api.Assertions.assertThat;
3334
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3435
import static org.assertj.core.api.InstanceOfAssertFactories.type;
36+
import static org.awaitility.Awaitility.await;
3537

3638
class HttpClientStreamableHttpVersionNegotiationIntegrationTests {
3739

@@ -102,6 +104,13 @@ void usesLatestVersion() {
102104
McpSchema.CallToolResult response = client
103105
.callTool(McpSchema.CallToolRequest.builder("test-tool").arguments(Map.of()).build());
104106

107+
// The GET /mcp stream is opened asynchronously once the initialize response
108+
// creates the session, so wait for it to be recorded before asserting.
109+
await().atMost(Duration.ofSeconds(5))
110+
.untilAsserted(
111+
() -> assertThat(requestRecordingFilter.getCalls()).filteredOn(c -> "GET".equals(c.method()))
112+
.hasSize(1));
113+
105114
var calls = requestRecordingFilter.getCalls();
106115

107116
assertThat(calls).filteredOn(c -> !c.body().contains("\"method\":\"initialize\""))

0 commit comments

Comments
 (0)