2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-13 01:47:32 +02:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2013-03-26 22:42:56 +01:00
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
const Readable = require('stream').Readable;
|
2013-03-26 22:42:56 +01:00
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
{
|
2013-03-26 22:42:56 +01:00
|
|
|
// First test, not reading when the readable is added.
|
2013-03-31 08:16:52 +02:00
|
|
|
// make sure that on('readable', ...) triggers a readable event.
|
2016-07-13 01:47:32 +02:00
|
|
|
const r = new Readable({
|
2013-03-26 22:42:56 +01:00
|
|
|
highWaterMark: 3
|
|
|
|
});
|
|
|
|
|
2017-02-03 20:54:19 +01:00
|
|
|
r._read = common.mustNotCall();
|
2013-03-26 22:42:56 +01:00
|
|
|
|
|
|
|
// This triggers a 'readable' event, which is lost.
|
2016-01-26 00:00:06 +01:00
|
|
|
r.push(Buffer.from('blerg'));
|
2013-03-26 22:42:56 +01:00
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-03-31 08:16:52 +02:00
|
|
|
// we're testing what we think we are
|
|
|
|
assert(!r._readableState.reading);
|
2016-07-13 01:47:32 +02:00
|
|
|
r.on('readable', common.mustCall(function() {}));
|
2016-11-04 22:04:00 +01:00
|
|
|
}, 1);
|
2016-07-13 01:47:32 +02:00
|
|
|
}
|
2013-03-26 22:42:56 +01:00
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
{
|
2013-03-26 22:42:56 +01:00
|
|
|
// second test, make sure that readable is re-emitted if there's
|
|
|
|
// already a length, while it IS reading.
|
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
const r = new Readable({
|
2013-03-26 22:42:56 +01:00
|
|
|
highWaterMark: 3
|
|
|
|
});
|
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
r._read = common.mustCall(function(n) {});
|
2013-03-26 22:42:56 +01:00
|
|
|
|
|
|
|
// This triggers a 'readable' event, which is lost.
|
2016-01-26 00:00:06 +01:00
|
|
|
r.push(Buffer.from('bl'));
|
2013-03-26 22:42:56 +01:00
|
|
|
|
2013-03-31 08:16:52 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
// assert we're testing what we think we are
|
|
|
|
assert(r._readableState.reading);
|
2016-07-13 01:47:32 +02:00
|
|
|
r.on('readable', common.mustCall(function() {}));
|
2016-11-04 22:04:00 +01:00
|
|
|
}, 1);
|
2016-07-13 01:47:32 +02:00
|
|
|
}
|
2013-03-27 06:43:53 +01:00
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
{
|
2013-03-27 06:43:53 +01:00
|
|
|
// Third test, not reading when the stream has not passed
|
|
|
|
// the highWaterMark but *has* reached EOF.
|
2016-07-13 01:47:32 +02:00
|
|
|
const r = new Readable({
|
2013-03-27 06:43:53 +01:00
|
|
|
highWaterMark: 30
|
|
|
|
});
|
|
|
|
|
2017-02-03 20:54:19 +01:00
|
|
|
r._read = common.mustNotCall();
|
2013-03-31 08:16:52 +02:00
|
|
|
|
2013-03-27 06:43:53 +01:00
|
|
|
// This triggers a 'readable' event, which is lost.
|
2016-01-26 00:00:06 +01:00
|
|
|
r.push(Buffer.from('blerg'));
|
2013-03-27 06:43:53 +01:00
|
|
|
r.push(null);
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-03-31 08:16:52 +02:00
|
|
|
// assert we're testing what we think we are
|
|
|
|
assert(!r._readableState.reading);
|
2016-07-13 01:47:32 +02:00
|
|
|
r.on('readable', common.mustCall(function() {}));
|
2016-11-04 22:04:00 +01:00
|
|
|
}, 1);
|
2016-07-13 01:47:32 +02:00
|
|
|
}
|