-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zlib: fix interaction of flushing and needDrain
Backport-PR-URL: #14571 Backport-Reviewed-By: James M Snell <[email protected]> Fixes: #14523 PR-URL: #14527 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/14523. | ||
// Checks that flushes interact properly with writableState.needDrain, | ||
// even if no flush callback was passed. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const zlib = require('zlib'); | ||
|
||
const zipper = zlib.createGzip({ highWaterMark: 16384 }); | ||
const unzipper = zlib.createGunzip(); | ||
zipper.pipe(unzipper); | ||
|
||
zipper.write('A'.repeat(17000)); | ||
zipper.flush(); | ||
|
||
let received = 0; | ||
unzipper.on('data', common.mustCall((d) => { | ||
received += d.length; | ||
}, 2)); | ||
|
||
// Properly `.end()`ing the streams would interfere with checking that | ||
// `.flush()` works. | ||
process.on('exit', () => { | ||
assert.strictEqual(received, 17000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const zlib = require('zlib'); | ||
|
||
const { | ||
Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH | ||
} = zlib.constants; | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
async function getOutput(...sequenceOfFlushes) { | ||
const zipper = zlib.createGzip({ highWaterMark: 16384 }); | ||
|
||
zipper.write('A'.repeat(17000)); | ||
for (const flush of sequenceOfFlushes) { | ||
zipper.flush(flush); | ||
} | ||
|
||
const data = []; | ||
|
||
return new Promise((resolve) => { | ||
zipper.on('data', common.mustCall((d) => { | ||
data.push(d); | ||
if (data.length === 2) resolve(Buffer.concat(data)); | ||
}, 2)); | ||
}); | ||
} | ||
|
||
(async function() { | ||
assert.deepStrictEqual(await getOutput(Z_SYNC_FLUSH), | ||
await getOutput(Z_SYNC_FLUSH, Z_PARTIAL_FLUSH)); | ||
assert.deepStrictEqual(await getOutput(Z_SYNC_FLUSH), | ||
await getOutput(Z_PARTIAL_FLUSH, Z_SYNC_FLUSH)); | ||
|
||
assert.deepStrictEqual(await getOutput(Z_FINISH), | ||
await getOutput(Z_FULL_FLUSH, Z_FINISH)); | ||
assert.deepStrictEqual(await getOutput(Z_FINISH), | ||
await getOutput(Z_SYNC_FLUSH, Z_FINISH)); | ||
})(); |