xref: /third_party/node/test/parallel/test-stream-readable-infinite-read.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst { Readable } = require('stream');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst buf = Buffer.alloc(8192);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst readable = new Readable({
101cb0ef41Sopenharmony_ci  read: common.mustCall(function() {
111cb0ef41Sopenharmony_ci    this.push(buf);
121cb0ef41Sopenharmony_ci  }, 31)
131cb0ef41Sopenharmony_ci});
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cilet i = 0;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cireadable.on('readable', common.mustCall(function() {
181cb0ef41Sopenharmony_ci  if (i++ === 10) {
191cb0ef41Sopenharmony_ci    // We will just terminate now.
201cb0ef41Sopenharmony_ci    process.removeAllListeners('readable');
211cb0ef41Sopenharmony_ci    return;
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  const data = readable.read();
251cb0ef41Sopenharmony_ci  // TODO(mcollina): there is something odd in the highWaterMark logic
261cb0ef41Sopenharmony_ci  // investigate.
271cb0ef41Sopenharmony_ci  if (i === 1) {
281cb0ef41Sopenharmony_ci    assert.strictEqual(data.length, 8192 * 2);
291cb0ef41Sopenharmony_ci  } else {
301cb0ef41Sopenharmony_ci    assert.strictEqual(data.length, 8192 * 3);
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci}, 11));
33

Indexes created Thu Nov 07 10:32:03 CST 2024