Skip to content

Commit

Permalink
Fix closing for v8.x and v9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
maritz committed Sep 26, 2018
1 parent 75794dd commit 521863c
Showing 1 changed file with 23 additions and 7 deletions.
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

0 comments on commit 521863c

Please sign in to comment.