1+ import type { ListAsyncInvokesCommandOutput } from "@aws-sdk/client-bedrock-runtime" ;
12import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime" ;
23import { SignatureV4 } from "@smithy/signature-v4" ;
34import { toBase64 } from "@smithy/util-base64" ;
@@ -8,6 +9,9 @@ describe("BedrockRuntime", () => {
89 const client = new BedrockRuntime ( {
910 region : "us-west-2" ,
1011 credentials : aws ?. testCredentials ,
12+ requestHandler : {
13+ maxConcurrentStreams : 3 ,
14+ } ,
1115 } ) ;
1216
1317 let signerCredentialProviderSpy : any ;
@@ -69,6 +73,7 @@ describe("BedrockRuntime", () => {
6973 const inputEnd = new Promise ( ( r ) => {
7074 resolve = r ;
7175 } ) ;
76+ const listAsyncInvokesOutputs : ListAsyncInvokesCommandOutput [ ] = [ ] ;
7277
7378 const response = await client . invokeModelWithBidirectionalStream ( {
7479 modelId,
@@ -178,6 +183,15 @@ describe("BedrockRuntime", () => {
178183 } ,
179184 } ;
180185
186+ // At midpoint, fire parallel requests over the same client
187+ // to verify HTTP/2 session concurrency doesn't interfere with the ongoing stream.
188+ if ( it === 10 ) {
189+ const results = await Promise . all (
190+ Array . from ( { length : 8 } , ( ) => client . listAsyncInvokes ( { maxResults : 1 } ) )
191+ ) ;
192+ listAsyncInvokesOutputs . push ( ...results ) ;
193+ }
194+
181195 if ( it % 15 === 3 ) {
182196 yields . push ( "contentEnd" ) ;
183197 yield {
@@ -266,6 +280,40 @@ describe("BedrockRuntime", () => {
266280 "sessionEnd" ,
267281 ] ) ;
268282
283+ // Verify parallel requests completed successfully during the bidirectional stream.
284+ expect ( listAsyncInvokesOutputs ) . toHaveLength ( 8 ) ;
285+ for ( const result of listAsyncInvokesOutputs ) {
286+ expect ( result . $metadata . httpStatusCode ) . toBe ( 200 ) ;
287+ }
288+
289+ const h2SessionState = ( client . config . requestHandler as any ) . connectionManager ?. debug ?.( ) ;
290+ if ( h2SessionState ) {
291+ expect ( h2SessionState ) . toMatchObject ( {
292+ "https://bedrock-runtime.us-west-2.amazonaws.com/" : {
293+ sessions : [
294+ {
295+ active : expect . any ( Number ) ,
296+ id : expect . any ( Number ) ,
297+ maxConcurrent : 3 ,
298+ totalRequests : 3 ,
299+ } ,
300+ {
301+ active : expect . any ( Number ) ,
302+ id : expect . any ( Number ) ,
303+ maxConcurrent : 3 ,
304+ totalRequests : 3 ,
305+ } ,
306+ {
307+ active : expect . any ( Number ) ,
308+ id : expect . any ( Number ) ,
309+ maxConcurrent : 2 ,
310+ totalRequests : 2 ,
311+ } ,
312+ ] ,
313+ } ,
314+ } ) ;
315+ }
316+
269317 // There are no other response fields currently.
270318 // Therefore, there is no difference in assertions for WebSocket and HTTP2.
271319 expect ( response . body ) . toBeDefined ( ) ;
0 commit comments