Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Lam Wei Li <lam_wei_li@hotmail.com>
  • Loading branch information
Icehunter and lamweili committed Jul 30, 2022
1 parent 46a030a commit 38fe9fd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/compression.js
Expand Up @@ -329,11 +329,15 @@ describe('compression()', function () {
request.on('response', function (headers) {
assert.strictEqual(headers['content-encoding'], 'gzip')
})
var chunks = [];
request.on('data', function (chunk) {
// no-op without which the request will stay open and cause a test timeout
chunks.push(chunk);
})
request.on('end', function () {
closeHttp2(request, client, server, done)
zlib.gunzip(Buffer.concat(chunks), function(err, data) {
assert.strictEqual(data.toString(), 'hello, world')
closeHttp2(client, server, done)
})
})
request.end()
})
Expand Down Expand Up @@ -730,27 +734,23 @@ function createHttp2Client (port) {
return http2.connect('http://127.0.0.1:' + port)
}

function closeHttp2 (request, client, server, callback) {
function closeHttp2 (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 way of closing the connections
request.close(http2.constants.NGHTTP2_NO_ERROR, function () {
client.close(function () {
// force existing connections to time out after 1ms.
// this is done to force the server to close in some cases where it wouldn't do it otherwise.
server.close(function () {
callback()
})
})
})
}
}

Expand Down

0 comments on commit 38fe9fd

Please sign in to comment.