mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 10:27:12 +00:00

Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: https://github.com/nodejs/node/pull/12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
38 lines
932 B
JavaScript
38 lines
932 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const stream = require('stream');
|
|
|
|
const reader = new stream.Readable();
|
|
const writer1 = new stream.Writable();
|
|
const writer2 = new stream.Writable();
|
|
|
|
// 560000 is chosen here because it is larger than the (default) highWaterMark
|
|
// and will cause `.write()` to return false
|
|
// See: https://github.com/nodejs/node/issues/2323
|
|
const buffer = Buffer.allocUnsafe(560000);
|
|
|
|
reader._read = common.noop;
|
|
|
|
writer1._write = common.mustCall(function(chunk, encoding, cb) {
|
|
this.emit('chunk-received');
|
|
cb();
|
|
}, 1);
|
|
writer1.once('chunk-received', function() {
|
|
reader.unpipe(writer1);
|
|
reader.pipe(writer2);
|
|
reader.push(buffer);
|
|
setImmediate(function() {
|
|
reader.push(buffer);
|
|
setImmediate(function() {
|
|
reader.push(buffer);
|
|
});
|
|
});
|
|
});
|
|
|
|
writer2._write = common.mustCall(function(chunk, encoding, cb) {
|
|
cb();
|
|
}, 3);
|
|
|
|
reader.pipe(writer1);
|
|
reader.push(buffer);
|