Skip to content

Commit

Permalink
test: fix flaky test-readline-interface
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and MylesBorins committed Sep 10, 2017
1 parent 19f4486 commit a83b6e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
24 changes: 0 additions & 24 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,6 @@ function isWarned(emitter) {
}), delay * 2);
}

// Emit one line events when the delay between \r and \n is
// over the default crlfDelay but within the setting value
{
const fi = new FakeInput();
const delay = 125;
const crlfDelay = common.platformTimeout(1000);
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: terminal,
crlfDelay
});
let callCount = 0;
rli.on('line', function(line) {
callCount++;
});
fi.emit('data', '\r');
setTimeout(common.mustCall(() => {
fi.emit('data', '\n');
assert.strictEqual(callCount, 1);
rli.close();
}), delay);
}

// set crlfDelay to `Infinity` is allowed
{
const fi = new FakeInput();
Expand Down
26 changes: 25 additions & 1 deletion test/sequential/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// Flags: --expose_internals
'use strict';
require('../common');
const common = require('../common');

// These test cases are in `sequential` rather than the analogous test file in
// `parallel` because they become unrelaible under load. The unreliability under
Expand Down Expand Up @@ -83,4 +83,28 @@ FakeInput.prototype.end = () => {};
assert.strictEqual(callCount, expectedLines.length);
rli.close();
}

// Emit one line event when the delay between \r and \n is
// over the default crlfDelay but within the setting value.
{
const fi = new FakeInput();
const delay = 125;
const crlfDelay = common.platformTimeout(1000);
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: terminal,
crlfDelay
});
let callCount = 0;
rli.on('line', function(line) {
callCount++;
});
fi.emit('data', '\r');
setTimeout(common.mustCall(() => {
fi.emit('data', '\n');
assert.strictEqual(callCount, 1);
rli.close();
}), delay);
}
});

0 comments on commit a83b6e6

Please sign in to comment.