Skip to content

Commit 6dbe6bd

Browse files
BridgeARcodebytere
authored andcommitted
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. PR-URL: #31708 Fixes: #31094 Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1dae7dc commit 6dbe6bd

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

test/parallel/test-repl-history-navigation.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history');
1818
// Create an input stream specialized for testing an array of actions
1919
class ActionStream extends stream.Stream {
2020
run(data) {
21-
let reallyWait = true;
2221
const _iter = data[Symbol.iterator]();
2322
const doAction = () => {
2423
const next = _iter.next();
@@ -34,12 +33,7 @@ class ActionStream extends stream.Stream {
3433
} else {
3534
this.emit('data', `${action}`);
3635
}
37-
if (action === WAIT && reallyWait) {
38-
setTimeout(doAction, common.platformTimeout(50));
39-
reallyWait = false;
40-
} else {
41-
setImmediate(doAction);
42-
}
36+
setImmediate(doAction);
4337
};
4438
doAction();
4539
}
@@ -67,6 +61,8 @@ const WAIT = '€';
6761

6862
const prev = process.features.inspector;
6963

64+
let completions = 0;
65+
7066
const tests = [
7167
{ // Creates few history to navigate for
7268
env: { NODE_REPL_HISTORY: defaultHistoryPath },
@@ -435,12 +431,11 @@ const tests = [
435431
env: { NODE_REPL_HISTORY: defaultHistoryPath },
436432
completer(line, callback) {
437433
if (line.endsWith(WAIT)) {
438-
setTimeout(
439-
callback,
440-
common.platformTimeout(40),
441-
null,
442-
[[`${WAIT}WOW`], line]
443-
);
434+
if (completions++ === 0) {
435+
callback(null, [[`${WAIT}WOW`], line]);
436+
} else {
437+
setTimeout(callback, 1000, null, [[`${WAIT}WOW`], line]).unref();
438+
}
444439
} else {
445440
callback(null, [[' Always visible'], line]);
446441
}

0 commit comments

Comments
 (0)