@@ -311,21 +311,22 @@ describe('compression()', function () {
311
311
312
312
if ( http2 ) {
313
313
it ( 'should work with http2 server' , function ( done ) {
314
- createHttp2Server ( { threshold : 0 } , function ( req , res ) {
314
+ var server = createHttp2Server ( { threshold : 0 } , function ( req , res ) {
315
315
res . setHeader ( 'Content-Type' , 'text/plain' )
316
316
res . end ( 'hello, world' )
317
317
} )
318
-
319
- var client = createHttp2Client ( )
320
- var request = client . request ( {
321
- 'Accept-Encoding' : 'gzip'
322
- } )
323
- request . on ( 'response' , function ( headers ) {
324
- assert . equal ( headers [ 'content-encoding' ] , 'gzip' )
325
- client . destroy ( )
326
- done ( )
318
+ server . on ( 'listening' , function ( ) {
319
+ var client = createHttp2Client ( server . address ( ) . port )
320
+ var request = client . request ( {
321
+ 'Accept-Encoding' : 'gzip'
322
+ } )
323
+ request . on ( 'response' , function ( headers ) {
324
+ assert . equal ( headers [ 'content-encoding' ] , 'gzip' )
325
+ client . destroy ( )
326
+ done ( )
327
+ } )
328
+ request . end ( )
327
329
} )
328
- request . end ( )
329
330
} )
330
331
}
331
332
@@ -702,12 +703,12 @@ function createHttp2Server (opts, fn) {
702
703
fn ( req , res )
703
704
} )
704
705
} )
705
- server . listen ( 8443 , '127.0.0.1' )
706
+ server . listen ( 0 , '127.0.0.1' )
706
707
return server
707
708
}
708
709
709
- function createHttp2Client ( ) {
710
- var client = http2 . connect ( 'http://127.0.0.1:8443' )
710
+ function createHttp2Client ( port ) {
711
+ var client = http2 . connect ( 'http://127.0.0.1:' + port )
711
712
return client
712
713
}
713
714
0 commit comments