Skip to content

Commit 0216dbe

Browse files
addaleaxMyles Borins
authored and
Myles Borins
committed
test: remove timers from streams test
test-stream2-readable-empty-buffer-no-eof fails on resource-constrained machines due to its use of timers. Removing timers makes it more reliable and doesn’t affect the validity of the test, as it only uses relative timing relations. Failures were noticed on freebsd10-64 in CI. I am able to replicate the failure with `tools/test.py --repeat=100 -j 100`. When run alone, it passes reliably. Refs: #9359 PR-URL: hkttps://github.com//pull/9360 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ilkka Myller <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent c1aee02 commit 0216dbe

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

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

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44

55
const Readable = require('stream').Readable;
@@ -16,36 +16,35 @@ function test1() {
1616
//
1717
// note that this is very unusual. it only works for crypto streams
1818
// because the other side of the stream will call read(0) to cycle
19-
// data through openssl. that's why we set the timeouts to call
19+
// data through openssl. that's why setImmediate() is used to call
2020
// r.read(0) again later, otherwise there is no more work being done
2121
// and the process just exits.
2222

2323
const buf = Buffer.alloc(5, 'x');
2424
let reads = 5;
25-
const timeout = common.platformTimeout(50);
2625
r._read = function(n) {
2726
switch (reads--) {
28-
case 0:
29-
return r.push(null); // EOF
30-
case 1:
31-
return r.push(buf);
32-
case 2:
33-
setTimeout(r.read.bind(r, 0), timeout);
34-
return r.push(Buffer.alloc(0)); // Not-EOF!
35-
case 3:
36-
setTimeout(r.read.bind(r, 0), timeout);
37-
return process.nextTick(function() {
38-
return r.push(Buffer.alloc(0));
27+
case 5:
28+
return setImmediate(function() {
29+
return r.push(buf);
3930
});
4031
case 4:
41-
setTimeout(r.read.bind(r, 0), timeout);
42-
return setTimeout(function() {
32+
setImmediate(function() {
4333
return r.push(Buffer.alloc(0));
4434
});
45-
case 5:
46-
return setTimeout(function() {
47-
return r.push(buf);
35+
return setImmediate(r.read.bind(r, 0));
36+
case 3:
37+
setImmediate(r.read.bind(r, 0));
38+
return process.nextTick(function() {
39+
return r.push(Buffer.alloc(0));
4840
});
41+
case 2:
42+
setImmediate(r.read.bind(r, 0));
43+
return r.push(Buffer.alloc(0)); // Not-EOF!
44+
case 1:
45+
return r.push(buf);
46+
case 0:
47+
return r.push(null); // EOF
4948
default:
5049
throw new Error('unreachable');
5150
}

0 commit comments

Comments
 (0)