@@ -324,13 +324,7 @@ describe('compression()', function () {
324
324
} )
325
325
request . on ( 'response' , function ( headers ) {
326
326
assert . equal ( headers [ 'content-encoding' ] , 'gzip' )
327
- request . close ( http2 . constants . NGHTTP2_NO_ERROR , function ( ) {
328
- client . close ( function ( ) {
329
- server . close ( function ( ) {
330
- done ( )
331
- } )
332
- } )
333
- } )
327
+ closeHttp2 ( request , client , server , done )
334
328
} )
335
329
request . end ( )
336
330
} )
@@ -719,6 +713,28 @@ function createHttp2Client (port) {
719
713
return client
720
714
}
721
715
716
+ function closeHttp2 ( request , client , server , callback ) {
717
+ if ( typeof client . shutdown === 'function' ) {
718
+ // this is the node v8.x way of closing the connections
719
+ request . destroy ( http2 . constants . NGHTTP2_NO_ERROR , function ( ) {
720
+ client . shutdown ( { } , function ( ) {
721
+ server . close ( function ( ) {
722
+ callback ( )
723
+ } )
724
+ } )
725
+ } )
726
+ } else {
727
+ // this is the node v9.x onwards (hopefully) way of closing the connections
728
+ request . close ( http2 . constants . NGHTTP2_NO_ERROR , function ( ) {
729
+ client . close ( function ( ) {
730
+ server . close ( function ( ) {
731
+ callback ( )
732
+ } )
733
+ } )
734
+ } )
735
+ }
736
+ }
737
+
722
738
function shouldHaveBodyLength ( length ) {
723
739
return function ( res ) {
724
740
assert . equal ( res . text . length , length , 'should have body length of ' + length )
0 commit comments