Skip to content

Commit d6b0d79

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 941b354 commit d6b0d79

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 8 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;
@@ -23,6 +24,7 @@
2324
import org.apache.catalina.LifecycleException;
2425
import org.apache.catalina.LifecycleState;
2526
import org.apache.catalina.startup.Tomcat;
27+
import static org.awaitility.Awaitility.await;
2628
import org.junit.jupiter.api.AfterEach;
2729
import org.junit.jupiter.api.Test;
2830

@@ -75,6 +77,12 @@ void usesLatestVersion() {
7577
McpSchema.CallToolResult response = client
7678
.callTool(McpSchema.CallToolRequest.builder("test-tool").arguments(Map.of()).build());
7779

80+
// The GET /mcp stream is opened asynchronously once the initialize response
81+
// creates the session, so wait for it to be recorded before asserting.
82+
await().atMost(Duration.ofSeconds(5))
83+
.untilAsserted(() -> assertThat(requestRecordingFilter.getCalls()).filteredOn(c -> "GET".equals(c.method()))
84+
.hasSize(1));
85+
7886
var calls = requestRecordingFilter.getCalls();
7987

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

0 commit comments

Comments
 (0)