From dea959e8412d6924d1efe67fbd107ee41471ed21 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 28 Aug 2017 13:15:24 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/15066 Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- test/parallel/test-readline-interface.js | 24 -------------------- test/sequential/test-readline-interface.js | 26 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index bddbc2053ac3cb..e1be69af0c90f4 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -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(); diff --git a/test/sequential/test-readline-interface.js b/test/sequential/test-readline-interface.js index 915bcdd0c0750c..1e64d0aa934974 100644 --- a/test/sequential/test-readline-interface.js +++ b/test/sequential/test-readline-interface.js @@ -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 @@ -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); + } });