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';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const str = 'asdfasdfasdfasdfasdf';
|
const str = 'asdfasdfasdfasdfasdf';
|
||||||
@ -10,29 +10,25 @@ const r = new stream.Readable({
|
|||||||
});
|
});
|
||||||
|
|
||||||
let reads = 0;
|
let reads = 0;
|
||||||
let eofed = false;
|
|
||||||
let ended = false;
|
|
||||||
|
|
||||||
r._read = function(n) {
|
function _read() {
|
||||||
if (reads === 0) {
|
if (reads === 0) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
r.push(str);
|
r.push(str);
|
||||||
});
|
}, 1);
|
||||||
reads++;
|
reads++;
|
||||||
} else if (reads === 1) {
|
} else if (reads === 1) {
|
||||||
var ret = r.push(str);
|
var ret = r.push(str);
|
||||||
assert.strictEqual(ret, false);
|
assert.strictEqual(ret, false);
|
||||||
reads++;
|
reads++;
|
||||||
} else {
|
} else {
|
||||||
assert(!eofed);
|
|
||||||
eofed = true;
|
|
||||||
r.push(null);
|
r.push(null);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
r.on('end', function() {
|
r._read = common.mustCall(_read, 3);
|
||||||
ended = true;
|
|
||||||
});
|
r.on('end', common.mustCall(function() {}));
|
||||||
|
|
||||||
// push some data in to start.
|
// push some data in to start.
|
||||||
// we've never gotten any read event at this point.
|
// we've never gotten any read event at this point.
|
||||||
@ -55,10 +51,3 @@ r.once('readable', function() {
|
|||||||
chunk = r.read();
|
chunk = r.read();
|
||||||
assert.strictEqual(chunk, null);
|
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