Skip to content

Commit

Permalink
test: refactor test-stream-big-push
Browse files Browse the repository at this point in the history
* use common.mustCall()
* specify setTimeout() duration of 1ms
* remove unused `n` function argument

PR-URL: #10226
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
Trott authored and italoacasas committed Dec 14, 2016
1 parent 9f6f0f7 commit b79e83e
Showing 1 changed file with 7 additions and 18 deletions.
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);
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');
});

0 comments on commit b79e83e

Please sign in to comment.