Skip to content

Commit 521863c

Browse files
Moritz Petersmaritz
Moritz Peters
authored andcommitted
Fix closing for v8.x and v9.x
1 parent 75794dd commit 521863c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

test/compression.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,7 @@ describe('compression()', function () {
324324
})
325325
request.on('response', function (headers) {
326326
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)
334328
})
335329
request.end()
336330
})
@@ -719,6 +713,28 @@ function createHttp2Client (port) {
719713
return client
720714
}
721715

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+
722738
function shouldHaveBodyLength (length) {
723739
return function (res) {
724740
assert.equal(res.text.length, length, 'should have body length of ' + length)

0 commit comments

Comments
 (0)