test: refactor test-stream-big-push
* use common.mustCall() * specify setTimeout() duration of 1ms * remove unused `n` function argument PR-URL: https://github.com/nodejs/node/pull/10226 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
9f6f0f748c
commit
b79e83e7f6
@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const stream = require('stream');
|
||||
const str = 'asdfasdfasdfasdfasdf';
|
||||
@ -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.
|
||||
@ -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');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user