11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst zlib = require('zlib'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst bigData = Buffer.alloc(10240, 'x'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst opts = { 91cb0ef41Sopenharmony_ci level: 0, 101cb0ef41Sopenharmony_ci highWaterMark: 16 111cb0ef41Sopenharmony_ci}; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst deflater = zlib.createDeflate(opts); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// Shim deflater.flush so we can count times executed 161cb0ef41Sopenharmony_cilet flushCount = 0; 171cb0ef41Sopenharmony_cilet drainCount = 0; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst flush = deflater.flush; 201cb0ef41Sopenharmony_cideflater.flush = function(kind, callback) { 211cb0ef41Sopenharmony_ci flushCount++; 221cb0ef41Sopenharmony_ci flush.call(this, kind, callback); 231cb0ef41Sopenharmony_ci}; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cideflater.write(bigData); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst ws = deflater._writableState; 281cb0ef41Sopenharmony_ciconst beforeFlush = ws.needDrain; 291cb0ef41Sopenharmony_cilet afterFlush = ws.needDrain; 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cideflater.on('data', () => { 321cb0ef41Sopenharmony_ci}); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cideflater.flush(function(err) { 351cb0ef41Sopenharmony_ci afterFlush = ws.needDrain; 361cb0ef41Sopenharmony_ci}); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_cideflater.on('drain', function() { 391cb0ef41Sopenharmony_ci drainCount++; 401cb0ef41Sopenharmony_ci}); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciprocess.once('exit', function() { 431cb0ef41Sopenharmony_ci assert.strictEqual( 441cb0ef41Sopenharmony_ci beforeFlush, true); 451cb0ef41Sopenharmony_ci assert.strictEqual( 461cb0ef41Sopenharmony_ci afterFlush, false); 471cb0ef41Sopenharmony_ci assert.strictEqual( 481cb0ef41Sopenharmony_ci drainCount, 1); 491cb0ef41Sopenharmony_ci assert.strictEqual( 501cb0ef41Sopenharmony_ci flushCount, 1); 511cb0ef41Sopenharmony_ci}); 52