Skip to content

Commit dea959e

Browse files
TrottMylesBorins
authored andcommitted
test: fix flaky test-readline-interface
Move test reliant on timer triggering in a timely fahion from parallel to sequential. The test can fail under high load when the timer is triggered too late and the `\r` and `\n` are treated as separate lines. PR-URL: #15066 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent f113d73 commit dea959e

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

test/parallel/test-readline-interface.js

-24
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,6 @@ function isWarned(emitter) {
291291
}), delay * 2);
292292
}
293293

294-
// Emit one line events when the delay between \r and \n is
295-
// over the default crlfDelay but within the setting value
296-
{
297-
const fi = new FakeInput();
298-
const delay = 125;
299-
const crlfDelay = common.platformTimeout(1000);
300-
const rli = new readline.Interface({
301-
input: fi,
302-
output: fi,
303-
terminal: terminal,
304-
crlfDelay
305-
});
306-
let callCount = 0;
307-
rli.on('line', function(line) {
308-
callCount++;
309-
});
310-
fi.emit('data', '\r');
311-
setTimeout(common.mustCall(() => {
312-
fi.emit('data', '\n');
313-
assert.strictEqual(callCount, 1);
314-
rli.close();
315-
}), delay);
316-
}
317-
318294
// set crlfDelay to `Infinity` is allowed
319295
{
320296
const fi = new FakeInput();

test/sequential/test-readline-interface.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
// Flags: --expose_internals
2323
'use strict';
24-
require('../common');
24+
const common = require('../common');
2525

2626
// These test cases are in `sequential` rather than the analogous test file in
2727
// `parallel` because they become unrelaible under load. The unreliability under
@@ -83,4 +83,28 @@ FakeInput.prototype.end = () => {};
8383
assert.strictEqual(callCount, expectedLines.length);
8484
rli.close();
8585
}
86+
87+
// Emit one line event when the delay between \r and \n is
88+
// over the default crlfDelay but within the setting value.
89+
{
90+
const fi = new FakeInput();
91+
const delay = 125;
92+
const crlfDelay = common.platformTimeout(1000);
93+
const rli = new readline.Interface({
94+
input: fi,
95+
output: fi,
96+
terminal: terminal,
97+
crlfDelay
98+
});
99+
let callCount = 0;
100+
rli.on('line', function(line) {
101+
callCount++;
102+
});
103+
fi.emit('data', '\r');
104+
setTimeout(common.mustCall(() => {
105+
fi.emit('data', '\n');
106+
assert.strictEqual(callCount, 1);
107+
rli.close();
108+
}), delay);
109+
}
86110
});

0 commit comments

Comments
 (0)