Skip to content

Commit eb2e280

Browse files
Moritz Petersmaritz
authored andcommitted
Fix port in tests to be assigned automatically
1 parent 655bbe9 commit eb2e280

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

test/compression.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,22 @@ describe('compression()', function () {
311311

312312
if (http2) {
313313
it('should work with http2 server', function (done) {
314-
createHttp2Server({ threshold: 0 }, function (req, res) {
314+
var server = createHttp2Server({ threshold: 0 }, function (req, res) {
315315
res.setHeader('Content-Type', 'text/plain')
316316
res.end('hello, world')
317317
})
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()
327329
})
328-
request.end()
329330
})
330331
}
331332

@@ -702,12 +703,12 @@ function createHttp2Server (opts, fn) {
702703
fn(req, res)
703704
})
704705
})
705-
server.listen(8443, '127.0.0.1')
706+
server.listen(0, '127.0.0.1')
706707
return server
707708
}
708709

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)
711712
return client
712713
}
713714

0 commit comments

Comments
 (0)