Skip to content
Prev Previous commit
Next Next commit
Fix closing for v8.x and v9.x
  • Loading branch information
Moritz Peters authored and maritz committed Sep 26, 2018
commit 521863cb435a9ce258fb6f477f031a7ed7e1cec3
30 changes: 23 additions & 7 deletions test/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,7 @@ describe('compression()', function () {
})
request.on('response', function (headers) {
assert.equal(headers['content-encoding'], 'gzip')
request.close(http2.constants.NGHTTP2_NO_ERROR, function () {
client.close(function () {
server.close(function () {
done()
})
})
})
closeHttp2(request, client, server, done)
})
request.end()
})
Expand Down Expand Up @@ -719,6 +713,28 @@ function createHttp2Client (port) {
return client
}

function closeHttp2 (request, client, server, callback) {
if (typeof client.shutdown === 'function') {
// this is the node v8.x way of closing the connections
request.destroy(http2.constants.NGHTTP2_NO_ERROR, function () {
client.shutdown({}, function () {
server.close(function () {
callback()
})
})
})
} else {
// this is the node v9.x onwards (hopefully) way of closing the connections
request.close(http2.constants.NGHTTP2_NO_ERROR, function () {
client.close(function () {
server.close(function () {
callback()
})
})
})
}
}

function shouldHaveBodyLength (length) {
return function (res) {
assert.equal(res.text.length, length, 'should have body length of ' + length)
Expand Down