Skip to content

Commit be3d929

Browse files
fix: correct SSE retry timing test to track GET requests only
The test was incorrectly measuring timing between all requests (POST and GET), but the retry field only applies to GET SSE stream reconnections. Changes: - Only track timestamps and Last-Event-ID for GET requests - Return 202 Accepted for notifications to trigger client GET stream - Add eventsource-parser dependency
1 parent 8a4601d commit be3d929

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"dependencies": {
4646
"@modelcontextprotocol/sdk": "^1.22.0",
4747
"commander": "^14.0.2",
48+
"eventsource-parser": "^3.0.6",
4849
"express": "^5.1.0",
4950
"lefthook": "^2.0.2",
5051
"zod": "^3.25.76"

src/scenarios/client/sse-retry.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ export class SSERetryScenario implements Scenario {
7676
req: http.IncomingMessage,
7777
res: http.ServerResponse
7878
): void {
79-
const timestamp = performance.now();
80-
this.connectionTimestamps.push(timestamp);
79+
if (req.method === 'GET') {
80+
// Track timing and Last-Event-ID only for GET requests
81+
// since retry field only applies to SSE stream reconnections
82+
const timestamp = performance.now();
83+
this.connectionTimestamps.push(timestamp);
8184

82-
// Track Last-Event-ID header
83-
const lastEventId = req.headers['last-event-id'] as string | undefined;
84-
this.lastEventIds.push(lastEventId);
85+
const lastEventId = req.headers['last-event-id'] as string | undefined;
86+
this.lastEventIds.push(lastEventId);
8587

86-
if (req.method === 'GET') {
8788
// Handle SSE stream request
8889
this.handleSSEStream(req, res);
8990
} else if (req.method === 'POST') {
@@ -174,6 +175,11 @@ export class SSERetryScenario implements Scenario {
174175
setTimeout(() => {
175176
res.end();
176177
}, 100);
178+
} else if (request.id === undefined) {
179+
// Notifications (no id) - return 202 Accepted
180+
// This triggers the client to start a GET SSE stream
181+
res.writeHead(202);
182+
res.end();
177183
} else {
178184
// For other requests, send a simple JSON response
179185
res.writeHead(200, { 'Content-Type': 'application/json' });

0 commit comments

Comments
 (0)