From 2dc5258ddfb206163b724dc38c1e14fee73d5ecd Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 9 Feb 2020 14:42:57 +0100 Subject: [PATCH 1/2] test: fix flaky parallel/test-repl-history-navigation test Two scenarios should be tested: 1. The completion is triggered and the result is printed before the next invocation. 2. The completion is triggered multiple times right after each other without waiting for the result. In that case only the last result should be printed. The first scenario did not need a timeout while the latter did not need a timeout for the second invocation. --- test/parallel/test-repl-history-navigation.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-repl-history-navigation.js b/test/parallel/test-repl-history-navigation.js index c4ca7f8147b021..34be3d0ffa38f7 100644 --- a/test/parallel/test-repl-history-navigation.js +++ b/test/parallel/test-repl-history-navigation.js @@ -18,7 +18,6 @@ const defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history'); // Create an input stream specialized for testing an array of actions class ActionStream extends stream.Stream { run(data) { - let reallyWait = true; const _iter = data[Symbol.iterator](); const doAction = () => { const next = _iter.next(); @@ -34,12 +33,7 @@ class ActionStream extends stream.Stream { } else { this.emit('data', `${action}`); } - if (action === WAIT && reallyWait) { - setTimeout(doAction, common.platformTimeout(50)); - reallyWait = false; - } else { - setImmediate(doAction); - } + setImmediate(doAction); }; doAction(); } @@ -67,6 +61,8 @@ const WAIT = '€'; const prev = process.features.inspector; +let completions = 0; + const tests = [ { // Creates few history to navigate for env: { NODE_REPL_HISTORY: defaultHistoryPath }, @@ -435,12 +431,16 @@ const tests = [ env: { NODE_REPL_HISTORY: defaultHistoryPath }, completer(line, callback) { if (line.endsWith(WAIT)) { - setTimeout( - callback, - common.platformTimeout(40), - null, - [[`${WAIT}WOW`], line] - ); + if (completions++ === 0) { + callback(null, [[`${WAIT}WOW`], line]); + } else { + setTimeout( + callback, + 1000, + null, + [[`${WAIT}WOW`], line] + ).unref(); + } } else { callback(null, [[' Always visible'], line]); } From a3314e2cefa3b8a44b6135857c451e24198ffbab Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 10 Feb 2020 12:57:31 +0100 Subject: [PATCH 2/2] fixup: address comment --- test/parallel/test-repl-history-navigation.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/parallel/test-repl-history-navigation.js b/test/parallel/test-repl-history-navigation.js index 34be3d0ffa38f7..8eda8e3ceceeef 100644 --- a/test/parallel/test-repl-history-navigation.js +++ b/test/parallel/test-repl-history-navigation.js @@ -434,12 +434,7 @@ const tests = [ if (completions++ === 0) { callback(null, [[`${WAIT}WOW`], line]); } else { - setTimeout( - callback, - 1000, - null, - [[`${WAIT}WOW`], line] - ).unref(); + setTimeout(callback, 1000, null, [[`${WAIT}WOW`], line]).unref(); } } else { callback(null, [[' Always visible'], line]);