1'use strict'; 2require('../common'); 3const assert = require('assert'); 4const zlib = require('zlib'); 5 6const bigData = Buffer.alloc(10240, 'x'); 7 8const opts = { 9 level: 0, 10 highWaterMark: 16 11}; 12 13const deflater = zlib.createDeflate(opts); 14 15// Shim deflater.flush so we can count times executed 16let flushCount = 0; 17let drainCount = 0; 18 19const flush = deflater.flush; 20deflater.flush = function(kind, callback) { 21 flushCount++; 22 flush.call(this, kind, callback); 23}; 24 25deflater.write(bigData); 26 27const ws = deflater._writableState; 28const beforeFlush = ws.needDrain; 29let afterFlush = ws.needDrain; 30 31deflater.flush(function(err) { 32 afterFlush = ws.needDrain; 33}); 34 35deflater.on('drain', function() { 36 drainCount++; 37}); 38 39process.once('exit', function() { 40 assert.strictEqual( 41 beforeFlush, true); 42 assert.strictEqual( 43 afterFlush, false); 44 assert.strictEqual( 45 drainCount, 1); 46 assert.strictEqual( 47 flushCount, 1); 48}); 49