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. PR-URL: https://github.com/nodejs/node/pull/17401 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
a322b8e316
commit
e1054abea0
@ -118,15 +118,6 @@ Tests whether `name` and `expected` are part of a raised warning.
|
|||||||
|
|
||||||
Checks if `pathname` exists
|
Checks if `pathname` exists
|
||||||
|
|
||||||
### fires(promise, [error], [timeoutMs])
|
|
||||||
* promise [<Promise]
|
|
||||||
* error [<String] default = 'timeout'
|
|
||||||
* timeoutMs [<Number] default = 100
|
|
||||||
|
|
||||||
Returns a new promise that will propagate `promise` resolution or rejection if
|
|
||||||
that happens within the `timeoutMs` timespan, or rejects with `error` as
|
|
||||||
a reason otherwise.
|
|
||||||
|
|
||||||
### getArrayBufferViews(buf)
|
### getArrayBufferViews(buf)
|
||||||
* `buf` [<Buffer>]
|
* `buf` [<Buffer>]
|
||||||
* return [<ArrayBufferView[]>]
|
* return [<ArrayBufferView[]>]
|
||||||
|
@ -850,32 +850,6 @@ function restoreWritable(name) {
|
|||||||
delete process[name].writeTimes;
|
delete process[name].writeTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onResolvedOrRejected(promise, callback) {
|
|
||||||
return promise.then((result) => {
|
|
||||||
callback();
|
|
||||||
return result;
|
|
||||||
}, (error) => {
|
|
||||||
callback();
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function timeoutPromise(error, timeoutMs) {
|
|
||||||
let clearCallback = null;
|
|
||||||
let done = false;
|
|
||||||
const promise = onResolvedOrRejected(new Promise((resolve, reject) => {
|
|
||||||
const timeout = setTimeout(() => reject(error), timeoutMs);
|
|
||||||
clearCallback = () => {
|
|
||||||
if (done)
|
|
||||||
return;
|
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
}), () => done = true);
|
|
||||||
promise.clear = clearCallback;
|
|
||||||
return promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
|
exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
|
||||||
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
|
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
|
||||||
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
|
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
|
||||||
@ -889,19 +863,3 @@ exports.firstInvalidFD = function firstInvalidFD() {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
return fd;
|
return fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fires = function fires(promise, error, timeoutMs) {
|
|
||||||
if (!timeoutMs && util.isNumber(error)) {
|
|
||||||
timeoutMs = error;
|
|
||||||
error = null;
|
|
||||||
}
|
|
||||||
if (!error)
|
|
||||||
error = 'timeout';
|
|
||||||
if (!timeoutMs)
|
|
||||||
timeoutMs = 100;
|
|
||||||
const timeout = timeoutPromise(error, timeoutMs);
|
|
||||||
return Promise.race([
|
|
||||||
onResolvedOrRejected(promise, () => timeout.clear()),
|
|
||||||
timeout
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
@ -216,7 +216,7 @@ class InspectorSession {
|
|||||||
waitForNotification(methodOrPredicate, description) {
|
waitForNotification(methodOrPredicate, description) {
|
||||||
const desc = description || methodOrPredicate;
|
const desc = description || methodOrPredicate;
|
||||||
const message = `Timed out waiting for matching notification (${desc}))`;
|
const message = `Timed out waiting for matching notification (${desc}))`;
|
||||||
return common.fires(
|
return fires(
|
||||||
this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT);
|
this._asyncWaitForNotification(methodOrPredicate), message, TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ class NodeInstance {
|
|||||||
const instance = new NodeInstance(
|
const instance = new NodeInstance(
|
||||||
[], `${scriptContents}\nprocess._rawDebug('started');`, undefined);
|
[], `${scriptContents}\nprocess._rawDebug('started');`, undefined);
|
||||||
const msg = 'Timed out waiting for process to start';
|
const msg = 'Timed out waiting for process to start';
|
||||||
while (await common.fires(instance.nextStderrString(), msg, TIMEOUT) !==
|
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !==
|
||||||
'started') {}
|
'started') {}
|
||||||
process._debugProcess(instance._process.pid);
|
process._debugProcess(instance._process.pid);
|
||||||
return instance;
|
return instance;
|
||||||
@ -412,6 +412,43 @@ function readMainScriptSource() {
|
|||||||
return fs.readFileSync(_MAINSCRIPT, 'utf8');
|
return fs.readFileSync(_MAINSCRIPT, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onResolvedOrRejected(promise, callback) {
|
||||||
|
return promise.then((result) => {
|
||||||
|
callback();
|
||||||
|
return result;
|
||||||
|
}, (error) => {
|
||||||
|
callback();
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function timeoutPromise(error, timeoutMs) {
|
||||||
|
let clearCallback = null;
|
||||||
|
let done = false;
|
||||||
|
const promise = onResolvedOrRejected(new Promise((resolve, reject) => {
|
||||||
|
const timeout = setTimeout(() => reject(error), timeoutMs);
|
||||||
|
clearCallback = () => {
|
||||||
|
if (done)
|
||||||
|
return;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
}), () => done = true);
|
||||||
|
promise.clear = clearCallback;
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a new promise that will propagate `promise` resolution or rejection
|
||||||
|
// if that happens within the `timeoutMs` timespan, or rejects with `error` as
|
||||||
|
// a reason otherwise.
|
||||||
|
function fires(promise, error, timeoutMs) {
|
||||||
|
const timeout = timeoutPromise(error, timeoutMs);
|
||||||
|
return Promise.race([
|
||||||
|
onResolvedOrRejected(promise, () => timeout.clear()),
|
||||||
|
timeout
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mainScriptPath: _MAINSCRIPT,
|
mainScriptPath: _MAINSCRIPT,
|
||||||
readMainScriptSource,
|
readMainScriptSource,
|
||||||
|
@ -36,7 +36,7 @@ class REPLStream extends common.ArrayStream {
|
|||||||
throw new Error('Currently waiting for response to another command');
|
throw new Error('Currently waiting for response to another command');
|
||||||
}
|
}
|
||||||
this.lines = [''];
|
this.lines = [''];
|
||||||
return common.fires(new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const onError = (err) => {
|
const onError = (err) => {
|
||||||
this.removeListener('line', onLine);
|
this.removeListener('line', onLine);
|
||||||
reject(err);
|
reject(err);
|
||||||
@ -50,7 +50,7 @@ class REPLStream extends common.ArrayStream {
|
|||||||
};
|
};
|
||||||
this.once('error', onError);
|
this.once('error', onError);
|
||||||
this.on('line', onLine);
|
this.on('line', onLine);
|
||||||
}), new Error(), 1000);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user