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.on('data', () => {
32});
33
34deflater.flush(function(err) {
35  afterFlush = ws.needDrain;
36});
37
38deflater.on('drain', function() {
39  drainCount++;
40});
41
42process.once('exit', function() {
43  assert.strictEqual(
44    beforeFlush, true);
45  assert.strictEqual(
46    afterFlush, false);
47  assert.strictEqual(
48    drainCount, 1);
49  assert.strictEqual(
50    flushCount, 1);
51});
52