test: move common.fires() to inspector-helper#17401
test: move common.fires() to inspector-helper#17401Trott wants to merge 1 commit intonodejs:masterfrom
Conversation
test/common/inspector-helper.js
Outdated
There was a problem hiding this comment.
Actually, this code for timeoutPromise is a little convoluted IMO - any reason we can't do.
const promisify = require('util').promisify;
const delay = promisify(setTimeout);
const timeoutPromise = async (error, timeoutMs, cancelToken) => {
await delay(ms);
if(cancelToken.cancelled) {
return;
}
throw error;
};Turns fires to:
function fires(promise, error, timeoutMs) {
var token = {};
return Promise.race([
onResolvedOrRejected(promise, () => token.cancelled = true),
timeoutPromise(error, timeoutMs, token)
]);
}If we want to preserve the onResolvedOnRejected behavior (which I'm not sure I understand) we can just use Promise.prototype.finally which is in V8 6.3
There was a problem hiding this comment.
No issues with further refactoring, but I'd prefer to do that in a separate PR.
benjamingr
left a comment
There was a problem hiding this comment.
Current code is a little complex IMO but actual changes LGTM
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.
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. PR-URL: nodejs#17401 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
|
Landed in e1054ab @benjamingr Would you be willing/interested to file a PR for the further refactoring you suggested? I'm happy to do it, but it seems right in your wheelhouse. (Alternatively, maybe you want to stash this one away for your next Code-and-Learn event?) |
|
This does not land cleanly on v9.x Could you please backport! |
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. PR-URL: nodejs#17401 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
|
Backported in #18096 |
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>
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>
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.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
test