11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst stream = require('stream');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst writable = new stream.Writable({
71cb0ef41Sopenharmony_ci  write: common.mustCall(function(chunk, encoding, cb) {
81cb0ef41Sopenharmony_ci    assert.strictEqual(
91cb0ef41Sopenharmony_ci      readable._readableState.awaitDrainWriters,
101cb0ef41Sopenharmony_ci      null,
111cb0ef41Sopenharmony_ci    );
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci    if (chunk.length === 32 * 1024) { // first chunk
141cb0ef41Sopenharmony_ci      readable.push(Buffer.alloc(34 * 1024)); // above hwm
151cb0ef41Sopenharmony_ci      // We should check if awaitDrain counter is increased in the next
161cb0ef41Sopenharmony_ci      // tick, because awaitDrain is incremented after this method finished
171cb0ef41Sopenharmony_ci      process.nextTick(() => {
181cb0ef41Sopenharmony_ci        assert.strictEqual(readable._readableState.awaitDrainWriters, writable);
191cb0ef41Sopenharmony_ci      });
201cb0ef41Sopenharmony_ci    }
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci    process.nextTick(cb);
231cb0ef41Sopenharmony_ci  }, 3)
241cb0ef41Sopenharmony_ci});
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci// A readable stream which produces two buffers.
271cb0ef41Sopenharmony_ciconst bufs = [Buffer.alloc(32 * 1024), Buffer.alloc(33 * 1024)]; // above hwm
281cb0ef41Sopenharmony_ciconst readable = new stream.Readable({
291cb0ef41Sopenharmony_ci  read: function() {
301cb0ef41Sopenharmony_ci    while (bufs.length > 0) {
311cb0ef41Sopenharmony_ci      this.push(bufs.shift());
321cb0ef41Sopenharmony_ci    }
331cb0ef41Sopenharmony_ci  }
341cb0ef41Sopenharmony_ci});
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cireadable.pipe(writable);
37