Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-stream-big-push #10226

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions test/parallel/test-stream-big-push.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const stream = require('stream');
const str = 'asdfasdfasdfasdfasdf';
Expand All @@ -10,29 +10,25 @@ const r = new stream.Readable({
});

let reads = 0;
let eofed = false;
let ended = false;

r._read = function(n) {
function _read() {
if (reads === 0) {
setTimeout(function() {
r.push(str);
});
}, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, why are we doing these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might just be me, but I find an unspecified duration or interval confusing. I always spend a moment wondering if it is a mistake. Did the original author simply forget to provide a value? Did they intend to use setImmediate() or even process.nextTick() instead of setTimeout()? And so on. By making it explicit, we at least make it clear that a 1ms timer is what was intended and not an error.

reads++;
} else if (reads === 1) {
var ret = r.push(str);
assert.strictEqual(ret, false);
reads++;
} else {
assert(!eofed);
eofed = true;
r.push(null);
}
};
}

r.on('end', function() {
ended = true;
});
r._read = common.mustCall(_read, 3);

r.on('end', common.mustCall(function() {}));

// push some data in to start.
// we've never gotten any read event at this point.
Expand All @@ -55,10 +51,3 @@ r.once('readable', function() {
chunk = r.read();
assert.strictEqual(chunk, null);
});

process.on('exit', function() {
assert(eofed);
assert(ended);
assert.strictEqual(reads, 2);
console.log('ok');
});