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: fix flaky streams test #4516

Closed
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
24 changes: 12 additions & 12 deletions test/parallel/test-stream2-readable-empty-buffer-no-eof.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';
require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

var Readable = require('stream').Readable;
const Readable = require('stream').Readable;

test1();
test2();

function test1() {
var r = new Readable();
const r = new Readable();

// should not end when we get a Buffer(0) or '' as the _read result
// that just means that there is *temporarily* no data, but to go
Expand All @@ -20,25 +20,25 @@ function test1() {
// r.read(0) again later, otherwise there is no more work being done
// and the process just exits.

var buf = new Buffer(5);
buf.fill('x');
var reads = 5;
const buf = Buffer(5).fill('x');
let reads = 5;
const timeout = common.platformTimeout(50);
r._read = function(n) {
switch (reads--) {
case 0:
return r.push(null); // EOF
case 1:
return r.push(buf);
case 2:
setTimeout(r.read.bind(r, 0), 50);
setTimeout(r.read.bind(r, 0), timeout);
return r.push(new Buffer(0)); // Not-EOF!
case 3:
setTimeout(r.read.bind(r, 0), 50);
setTimeout(r.read.bind(r, 0), timeout);
return process.nextTick(function() {
return r.push(new Buffer(0));
});
case 4:
setTimeout(r.read.bind(r, 0), 50);
setTimeout(r.read.bind(r, 0), timeout);
return setTimeout(function() {
return r.push(new Buffer(0));
});
Expand All @@ -51,9 +51,9 @@ function test1() {
}
};

var results = [];
const results = [];
function flow() {
var chunk;
let chunk;
while (null !== (chunk = r.read()))
results.push(chunk + '');
}
Expand Down