test: move common.fires() to inspector-helper · nodejs/node@2eb1aa8 · GitHub
Skip to content

Commit 2eb1aa8

Browse files
Trottevanlucas
authored andcommitted
test: move common.fires() to inspector-helper
common.fires() is specific to the inspector tests so move it to inspector-helper.js. The one REPL test that used common.fires() does not seem to need it. It provided a 1 second timeout for operations, but that timeout appears both arbitrary and ineffective as the test passes if it is reduced to even 1 millisecond. Backport-PR-URL: #18096 PR-URL: #17401 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 167e9c6 commit 2eb1aa8

3 files changed

Lines changed: 39 additions & 53 deletions

File tree

test/common/README.md

Lines changed: 0 additions & 9 deletions

test/common/index.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -866,32 +866,6 @@ function restoreWritable(name) {
866866
delete process[name].writeTimes;
867867
}
868868

869-
function onResolvedOrRejected(promise, callback) {
870-
return promise.then((result) => {
871-
callback();
872-
return result;
873-
}, (error) => {
874-
callback();
875-
throw error;
876-
});
877-
}
878-
879-
function timeoutPromise(error, timeoutMs) {
880-
let clearCallback = null;
881-
let done = false;
882-
const promise = onResolvedOrRejected(new Promise((resolve, reject) => {
883-
const timeout = setTimeout(() => reject(error), timeoutMs);
884-
clearCallback = () => {
885-
if (done)
886-
return;
887-
clearTimeout(timeout);
888-
resolve();
889-
};
890-
}), () => done = true);
891-
promise.clear = clearCallback;
892-
return promise;
893-
}
894-
895869
exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
896870
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
897871
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
@@ -905,19 +879,3 @@ exports.firstInvalidFD = function firstInvalidFD() {
905879
} catch (e) {}
906880
return fd;
907881
};
908-
909-
exports.fires = function fires(promise, error, timeoutMs) {
910-
if (!timeoutMs && util.isNumber(error)) {
911-
timeoutMs = error;
912-
error = null;
913-
}
914-
if (!error)
915-
error = 'timeout';
916-
if (!timeoutMs)
917-
timeoutMs = 100;
918-
const timeout = timeoutPromise(error, timeoutMs);
919-
return Promise.race([
920-
onResolvedOrRejected(promise, () => timeout.clear()),
921-
timeout
922-
]);
923-
};

test/common/inspector-helper.js

Lines changed: 39 additions & 2 deletions

0 commit comments

Comments
 (0)