Skip to content

Commit 38fe9fd

Browse files
Icehunterlamweili
andauthored
Apply suggestions from code review
Co-authored-by: Lam Wei Li <[email protected]>
1 parent 46a030a commit 38fe9fd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

test/compression.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,15 @@ describe('compression()', function () {
329329
request.on('response', function (headers) {
330330
assert.strictEqual(headers['content-encoding'], 'gzip')
331331
})
332+
var chunks = [];
332333
request.on('data', function (chunk) {
333-
// no-op without which the request will stay open and cause a test timeout
334+
chunks.push(chunk);
334335
})
335336
request.on('end', function () {
336-
closeHttp2(request, client, server, done)
337+
zlib.gunzip(Buffer.concat(chunks), function(err, data) {
338+
assert.strictEqual(data.toString(), 'hello, world')
339+
closeHttp2(client, server, done)
340+
})
337341
})
338342
request.end()
339343
})
@@ -730,27 +734,23 @@ function createHttp2Client (port) {
730734
return http2.connect('http://127.0.0.1:' + port)
731735
}
732736

733-
function closeHttp2 (request, client, server, callback) {
737+
function closeHttp2 (client, server, callback) {
734738
if (typeof client.shutdown === 'function') {
735739
// this is the node v8.x way of closing the connections
736-
request.destroy(http2.constants.NGHTTP2_NO_ERROR, function () {
737740
client.shutdown({}, function () {
738741
server.close(function () {
739742
callback()
740743
})
741744
})
742-
})
743745
} else {
744746
// this is the node v9.x onwards way of closing the connections
745-
request.close(http2.constants.NGHTTP2_NO_ERROR, function () {
746747
client.close(function () {
747748
// force existing connections to time out after 1ms.
748749
// this is done to force the server to close in some cases where it wouldn't do it otherwise.
749750
server.close(function () {
750751
callback()
751752
})
752753
})
753-
})
754754
}
755755
}
756756

0 commit comments

Comments
 (0)