Skip to content

Commit 68bafb8

Browse files
Trottjasnell
authored andcommitted
test: fix flaky streams test
Use common.platformTimeout() to fix flaky test-stream2-readable-empty-buffer-no-eofi on Raspberry Pis. Fixes: #4493 PR-URL: #4516 Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell<[email protected]>
1 parent 6ea8b01 commit 68bafb8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

test/parallel/test-stream2-readable-empty-buffer-no-eof.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
2-
require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

5-
var Readable = require('stream').Readable;
5+
const Readable = require('stream').Readable;
66

77
test1();
88
test2();
99

1010
function test1() {
11-
var r = new Readable();
11+
const r = new Readable();
1212

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

23-
var buf = new Buffer(5);
24-
buf.fill('x');
25-
var reads = 5;
23+
const buf = Buffer(5).fill('x');
24+
let reads = 5;
25+
const timeout = common.platformTimeout(50);
2626
r._read = function(n) {
2727
switch (reads--) {
2828
case 0:
2929
return r.push(null); // EOF
3030
case 1:
3131
return r.push(buf);
3232
case 2:
33-
setTimeout(r.read.bind(r, 0), 50);
33+
setTimeout(r.read.bind(r, 0), timeout);
3434
return r.push(new Buffer(0)); // Not-EOF!
3535
case 3:
36-
setTimeout(r.read.bind(r, 0), 50);
36+
setTimeout(r.read.bind(r, 0), timeout);
3737
return process.nextTick(function() {
3838
return r.push(new Buffer(0));
3939
});
4040
case 4:
41-
setTimeout(r.read.bind(r, 0), 50);
41+
setTimeout(r.read.bind(r, 0), timeout);
4242
return setTimeout(function() {
4343
return r.push(new Buffer(0));
4444
});
@@ -51,9 +51,9 @@ function test1() {
5151
}
5252
};
5353

54-
var results = [];
54+
const results = [];
5555
function flow() {
56-
var chunk;
56+
let chunk;
5757
while (null !== (chunk = r.read()))
5858
results.push(chunk + '');
5959
}

0 commit comments

Comments
 (0)