@@ -1320,21 +1320,15 @@ describe("StreamableHTTPServerTransport", () => {
13201320 body : JSON . stringify ( batchMessages ) ,
13211321 } ) ;
13221322
1323- // Mock sequential responses - send them in specific order
1323+ // Mock responses without enforcing specific order
13241324 jsonResponseTransport . onmessage = ( message ) => {
13251325 if ( 'method' in message && 'id' in message ) {
13261326 const responseMessage : JSONRPCMessage = {
13271327 jsonrpc : "2.0" ,
13281328 result : { value : `result-for-${ message . id } ` } ,
13291329 id : message . id ,
13301330 } ;
1331- // Send responses in order - req1 first, then req2
1332- if ( message . id === 'req1' ) {
1333- void jsonResponseTransport . send ( responseMessage ) ;
1334- } else {
1335- // Add a tiny delay to req2 to ensure it's processed after req1
1336- setTimeout ( ( ) => void jsonResponseTransport . send ( responseMessage ) , 5 ) ;
1337- }
1331+ void jsonResponseTransport . send ( responseMessage ) ;
13381332 }
13391333 } ;
13401334
@@ -1351,8 +1345,15 @@ describe("StreamableHTTPServerTransport", () => {
13511345 } )
13521346 ) ;
13531347
1348+ // Verify response was sent but don't assume specific order
13541349 expect ( mockResponse . end ) . toHaveBeenCalled ( ) ;
1355- expect ( mockResponse . end . mock . calls [ 0 ] [ 0 ] ) . toContain ( "result-for-req2" ) ;
1350+ const responseJson = JSON . parse ( mockResponse . end . mock . calls [ 0 ] [ 0 ] as string ) ;
1351+ expect ( Array . isArray ( responseJson ) ) . toBe ( true ) ;
1352+ expect ( responseJson ) . toHaveLength ( 2 ) ;
1353+
1354+ // Check each response exists separately without assuming order
1355+ expect ( responseJson ) . toContainEqual ( expect . objectContaining ( { id : "req1" , result : { value : "result-for-req1" } } ) ) ;
1356+ expect ( responseJson ) . toContainEqual ( expect . objectContaining ( { id : "req2" , result : { value : "result-for-req2" } } ) ) ;
13561357 } ) ;
13571358 } ) ;
13581359
0 commit comments