From b79e83e7f6458fe5bb180731a2fdb9341a22514e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 10 Dec 2016 21:43:39 -0800 Subject: [PATCH] test: refactor test-stream-big-push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Reviewed-By: Michaƫl Zasso --- test/parallel/test-stream-big-push.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-stream-big-push.js b/test/parallel/test-stream-big-push.js index d9b79ebafc1d08..27feef35ef536d 100644 --- a/test/parallel/test-stream-big-push.js +++ b/test/parallel/test-stream-big-push.js @@ -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'); -});