11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// Testing Readable Stream resumeScheduled state
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst { Readable, Writable } = require('stream');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci{
101cb0ef41Sopenharmony_ci  // pipe() test case
111cb0ef41Sopenharmony_ci  const r = new Readable({ read() {} });
121cb0ef41Sopenharmony_ci  const w = new Writable();
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  // resumeScheduled should start = `false`.
151cb0ef41Sopenharmony_ci  assert.strictEqual(r._readableState.resumeScheduled, false);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  // Calling pipe() should change the state value = true.
181cb0ef41Sopenharmony_ci  r.pipe(w);
191cb0ef41Sopenharmony_ci  assert.strictEqual(r._readableState.resumeScheduled, true);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  process.nextTick(common.mustCall(() => {
221cb0ef41Sopenharmony_ci    assert.strictEqual(r._readableState.resumeScheduled, false);
231cb0ef41Sopenharmony_ci  }));
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci{
271cb0ef41Sopenharmony_ci  // 'data' listener test case
281cb0ef41Sopenharmony_ci  const r = new Readable({ read() {} });
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  // resumeScheduled should start = `false`.
311cb0ef41Sopenharmony_ci  assert.strictEqual(r._readableState.resumeScheduled, false);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  r.push(Buffer.from([1, 2, 3]));
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  // Adding 'data' listener should change the state value
361cb0ef41Sopenharmony_ci  r.on('data', common.mustCall(() => {
371cb0ef41Sopenharmony_ci    assert.strictEqual(r._readableState.resumeScheduled, false);
381cb0ef41Sopenharmony_ci  }));
391cb0ef41Sopenharmony_ci  assert.strictEqual(r._readableState.resumeScheduled, true);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  process.nextTick(common.mustCall(() => {
421cb0ef41Sopenharmony_ci    assert.strictEqual(r._readableState.resumeScheduled, false);
431cb0ef41Sopenharmony_ci  }));
441cb0ef41Sopenharmony_ci}
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci{
471cb0ef41Sopenharmony_ci  // resume() test case
481cb0ef41Sopenharmony_ci  const r = new Readable({ read() {} });
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  // resumeScheduled should start = `false`.
511cb0ef41Sopenharmony_ci  assert.strictEqual(r._readableState.resumeScheduled, false);
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  // Calling resume() should change the state value.
541cb0ef41Sopenharmony_ci  r.resume();
551cb0ef41Sopenharmony_ci  assert.strictEqual(r._readableState.resumeScheduled, true);
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  r.on('resume', common.mustCall(() => {
581cb0ef41Sopenharmony_ci    // The state value should be `false` again
591cb0ef41Sopenharmony_ci    assert.strictEqual(r._readableState.resumeScheduled, false);
601cb0ef41Sopenharmony_ci  }));
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci  process.nextTick(common.mustCall(() => {
631cb0ef41Sopenharmony_ci    assert.strictEqual(r._readableState.resumeScheduled, false);
641cb0ef41Sopenharmony_ci  }));
651cb0ef41Sopenharmony_ci}
66