@@ -2,6 +2,7 @@ import { AbortController } from "@aws-sdk/abort-controller";
2
2
import { HttpRequest } from "@aws-sdk/protocol-http" ;
3
3
import { rejects } from "assert" ;
4
4
import http2 , { constants , Http2Stream } from "http2" ;
5
+ import { Duplex } from "stream" ;
5
6
6
7
import { NodeHttp2Handler } from "./node-http2-handler" ;
7
8
import { createMockHttp2Server , createResponseFunction , createResponseFunctionWithDelay } from "./server.mock" ;
@@ -375,6 +376,53 @@ describe(NodeHttp2Handler.name, () => {
375
376
} ) ;
376
377
} ) ;
377
378
379
+ it ( "will throw reasonable error when connection aborted abnormally" , async ( ) => {
380
+ nodeH2Handler = new NodeHttp2Handler ( ) ;
381
+ // Create a session by sending a request.
382
+ await nodeH2Handler . handle ( new HttpRequest ( getMockReqOptions ( ) ) , { } ) ;
383
+ const authority = `${ protocol } //${ hostname } :${ port } ` ;
384
+ // @ts -ignore: access private property
385
+ const session : ClientHttp2Session = nodeH2Handler . sessionCache . get ( authority ) [ 0 ] ;
386
+ const fakeStream = new Duplex ( ) ;
387
+ const fakeRstCode = 1 ;
388
+ // @ts -ignore: fake result code
389
+ fakeStream . rstCode = fakeRstCode ;
390
+ jest . spyOn ( session , "request" ) . mockImplementation ( ( ) => fakeStream ) ;
391
+ // @ts -ignore: access private property
392
+ nodeH2Handler . sessionCache . set ( `${ protocol } //${ hostname } :${ port } ` , [ session ] ) ;
393
+ // Delay response so that onabort is called earlier
394
+ setTimeout ( ( ) => {
395
+ fakeStream . emit ( "aborted" ) ;
396
+ } , 0 ) ;
397
+
398
+ await expect ( nodeH2Handler . handle ( new HttpRequest ( { ...getMockReqOptions ( ) } ) , { } ) ) . rejects . toHaveProperty (
399
+ "message" ,
400
+ `HTTP/2 stream is abnormally aborted in mid-communication with result code ${ fakeRstCode } .`
401
+ ) ;
402
+ } ) ;
403
+
404
+ it ( "will throw reasonable error when frameError is thrown" , async ( ) => {
405
+ nodeH2Handler = new NodeHttp2Handler ( ) ;
406
+ // Create a session by sending a request.
407
+ await nodeH2Handler . handle ( new HttpRequest ( getMockReqOptions ( ) ) , { } ) ;
408
+ const authority = `${ protocol } //${ hostname } :${ port } ` ;
409
+ // @ts -ignore: access private property
410
+ const session : ClientHttp2Session = nodeH2Handler . sessionCache . get ( authority ) [ 0 ] ;
411
+ const fakeStream = new Duplex ( ) ;
412
+ jest . spyOn ( session , "request" ) . mockImplementation ( ( ) => fakeStream ) ;
413
+ // @ts -ignore: access private property
414
+ nodeH2Handler . sessionCache . set ( `${ protocol } //${ hostname } :${ port } ` , [ session ] ) ;
415
+ // Delay response so that onabort is called earlier
416
+ setTimeout ( ( ) => {
417
+ fakeStream . emit ( "frameError" , "TYPE" , "CODE" , "ID" ) ;
418
+ } , 0 ) ;
419
+
420
+ await expect ( nodeH2Handler . handle ( new HttpRequest ( { ...getMockReqOptions ( ) } ) , { } ) ) . rejects . toHaveProperty (
421
+ "message" ,
422
+ `Frame type id TYPE in stream id ID has failed with code CODE.`
423
+ ) ;
424
+ } ) ;
425
+
378
426
describe ( "disableConcurrentStreams" , ( ) => {
379
427
beforeEach ( ( ) => {
380
428
nodeH2Handler = new NodeHttp2Handler ( {
0 commit comments