@@ -327,6 +327,14 @@ describe('compression()', function () {
327
327
} )
328
328
request . on ( 'response' , function ( headers ) {
329
329
assert . equal ( headers [ 'content-encoding' ] , 'gzip' )
330
+ } )
331
+ request . on ( 'error' , function ( error ) {
332
+ console . error ( 'An error event occurred on a http2 client request.' , error )
333
+ } )
334
+ request . on ( 'data' , function ( chunk ) {
335
+ // no-op without which the request will stay open and cause a test timeout
336
+ } )
337
+ request . on ( 'end' , function ( ) {
330
338
closeHttp2 ( request , client , server , done )
331
339
} )
332
340
request . end ( )
@@ -697,6 +705,12 @@ function createServer (opts, fn) {
697
705
function createHttp2Server ( opts , fn ) {
698
706
var _compression = compression ( opts )
699
707
var server = http2 . createServer ( function ( req , res ) {
708
+ req . on ( 'error' , function ( error ) {
709
+ console . error ( 'An error event occurred on a http2 request.' , error )
710
+ } )
711
+ res . on ( 'error' , function ( error ) {
712
+ console . error ( 'An error event occurred on a http2 response.' , error )
713
+ } )
700
714
_compression ( req , res , function ( err ) {
701
715
if ( err ) {
702
716
res . statusCode = err . status || 500
@@ -707,12 +721,21 @@ function createHttp2Server (opts, fn) {
707
721
fn ( req , res )
708
722
} )
709
723
} )
724
+ server . on ( 'error' , function ( error ) {
725
+ console . error ( 'An error event occurred on the http2 server.' , error )
726
+ } )
727
+ server . on ( 'sessionError' , function ( error ) {
728
+ console . error ( 'A sessionError event occurred on the http2 server.' , error )
729
+ } )
710
730
server . listen ( 0 , '127.0.0.1' )
711
731
return server
712
732
}
713
733
714
734
function createHttp2Client ( port ) {
715
735
var client = http2 . connect ( 'http://127.0.0.1:' + port )
736
+ client . on ( 'error' , function ( error ) {
737
+ console . error ( 'An error event occurred in the http2 client stream.' , error )
738
+ } )
716
739
return client
717
740
}
718
741
@@ -727,9 +750,14 @@ function closeHttp2 (request, client, server, callback) {
727
750
} )
728
751
} )
729
752
} else {
730
- // this is the node v9.x onwards (hopefully) way of closing the connections
753
+ // this is the node v9.x onwards way of closing the connections
731
754
request . close ( http2 . constants . NGHTTP2_NO_ERROR , function ( ) {
732
755
client . close ( function ( ) {
756
+ // force existing connections to time out after 1ms.
757
+ // this is done to force the server to close in some cases where it wouldn't do it otherwise.
758
+ server . setTimeout ( 1 , function ( ) {
759
+ console . warn ( 'An http2 connection timed out instead of being closed properly.' )
760
+ } )
733
761
server . close ( function ( ) {
734
762
callback ( )
735
763
} )
0 commit comments