Skip to content

Conversation

@devalibm
Copy link
Member

Comment on lines 2114 to 2151
@Test
public void testDuplicateRequestIdReturnsError() throws Exception {

String requestTemplate = """
{
"jsonrpc": "2.0",
"id": "%s",
"method": "tools/call",
"params": {
"name": "echo",
"arguments": {
"input": "Hello"
}
}
}
""";

// First request call
new HttpRequest(server, "/toolTest/mcp").requestProp("Accept", ACCEPT_HEADER)
.requestProp(MCP_PROTOCOL_HEADER, MCP_PROTOCOL_VERSION)
.requestProp("Mcp-Session-Id", client.getSessionId())
.jsonBody(requestTemplate)
.method("POST")
.expectCode(200)
.run(String.class);

// Second request - same ID while the first is likely still active
String duplicateResponse = new HttpRequest(server, "/toolTest/mcp").requestProp("Accept", ACCEPT_HEADER)
.requestProp(MCP_PROTOCOL_HEADER, MCP_PROTOCOL_VERSION)
.requestProp("Mcp-Session-Id", client.getSessionId())
.jsonBody(requestTemplate)
.method("POST")
.expectCode(200)
.run(String.class);

assertThat("Expected error for duplicate request ID", duplicateResponse, containsString("\"error\""));
assertThat("Expected specific error code for duplicate request ID", duplicateResponse, containsString("CWMCM0009E"));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things confuse me about this test:

  • requestTemplate looks like it should have an id substituted in place of the %s but it doesn't. This doesn't actually break the test since "%s" is a valid identifier and it is used in both requests.
  • HttpRequest.run waits for the response and returns it, so the first request should always be completed before the second one runs. Given that, I'm not sure how this test passes. It suggests we may not be removing the completed request.
    • It does mean that this test (non-concurrent requests with the same ID) is probably a good one to have, since it should catch if we're not cleaning up correctly, we just also need a test which actually does concurrent requests.
    • To test concurrent requests, you will need to do something like the cancellation tests.
  • I'm not sure why this test doesn't use McpClient.callMcp - it doesn't appear to be doing anything special?
  • When checking the for the error code, please also check for the id which should be included in the message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants