-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: rewrite inspector test helper #14460
Conversation
Newer helper uses port 0 by default. Also it should now be possible to run multiple children processes (no test uses this yet). |
Very nice! I've implemented something like this but for |
@TimothyGu I would really appreciate your suggestions. I've been thinking about having a test framework that can run tests both through WebSockets and JS bindings to improve the coverage. But I am also working on moving WS codepath to use JS bindings to talk to inspector - that should make JS bindings tests less important. |
return { length: bodyOffset + dataLen, message }; | ||
} | ||
|
||
function promiseWithTimeout(promise, message, multiplicator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be added to test/common/index.js, or you can just take my version instead :) https://github.com/TimothyGu/node/blob/15a8ff8f52a8e01f41e773ea1f4e970976625aac/test/common/index.js#L820-L838 (docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied you version - but the issue I noticed is that the test will not complete until the timeout is fired. I implemented the timeout clearing.
|
||
function checkHttpResponse(host, port, path) { | ||
return new Promise(function(resolve, reject) { | ||
const req = http.get({ host, port, path }, function(res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrow functions are preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
class InspectorSession { | ||
constructor(socket, instance) { | ||
this.instance_ = instance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Node.js private properties are usually prefixed with _
not postfixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
waitForNotification(methodOrPredicate, description) { | ||
const desc = description || methodOrPredicate; | ||
const message = `Timed out faiting for matching notification (${desc}))`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
matchesConsoleOutputNotification_(notification, type, values) { | ||
if (!(values instanceof Array)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.isArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
kill() { | ||
return this.enqueue_((callback) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is enqueue_
defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted "kill" (for now). It was copied from the old test and "enqueu_" is a primary reason the tests have to be rewritten :)
}); | ||
} | ||
|
||
static createChildProcess(inspectorFlags, scriptContents, scriptFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function intended to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it a standalone non-exported function.
runTests().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to use common.crashOnUnhandledRejection()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
(message) => this.onStderrLine(message))); | ||
|
||
this.shutdownPromise_ = new Promise((resolve) => { | ||
this.process_.on('exit', (exitCode, signal) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it doesn't matter most of the cases, but I prefer using once
instead of on
with promises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
console.log('[sent]', JSON.stringify(msg)); | ||
const messageBuf = Buffer.from(JSON.stringify(msg)); | ||
|
||
const wsHeaderBuf = Buffer.allocUnsafe(16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WS stuff should be factored out of this function (much like parseWSFrame
above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@TimothyGu Thank you for your review. Please take another look. I am more confident in this approach now so I will try to find time and port other tests now. |
test/common/index.js
Outdated
@@ -816,3 +816,28 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout'); | |||
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr'); | |||
exports.restoreStdout = restoreWritable.bind(null, 'stdout'); | |||
exports.restoreStderr = restoreWritable.bind(null, 'stderr'); | |||
|
|||
exports.fires = function fires(promise, error = 'timeout', timeoutMs = 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs should be added to test/common/README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I also ported a couple more test cases.
Note - I pushed a new change as a separate commit to make it easier to use the GitHub UI - I will do a proper rebase/squish before submitting the code.
test/common/index.js
Outdated
@@ -812,7 +812,49 @@ function restoreWritable(name) { | |||
delete process[name].writeTimes; | |||
} | |||
|
|||
function onResolvedOrRejected(promise, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you call this finally
as per https://github.com/tc39/proposal-promise-finally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally
is a reserved word. I considered promiseFinally
or onFinally
- but decided to be explicit...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One hackish way around that is to set the name property on the function after it is defined. E.g.
function onResolvedOrRejected(promise, callback) { /* ... */ }
onResolvedOrRejected.name = 'finally';
But I definitely do not see that as being critical.
CI: https://ci.nodejs.org/job/node-test-pull-request/9466/ I ported all the tests to a new framework. I also renamed test cases to remove "-inspector" from the file name - they all reside in the "inspector" folder so there is no need to repeat it in the file name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rebase...
// 1 second wait to make sure the inferior began running the script | ||
setTimeout(() => harness.runFrontendSession([shouldShutDown]).kill(), 1000); | ||
console.log(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging console.logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed :)
Performed a rebase. New CI: https://ci.nodejs.org/job/node-test-pull-request/9578/ |
Apparently, last CI run was cancelled. New CI: https://ci.nodejs.org/job/node-test-pull-request/9603/ |
CI did not show any relevant failures. This PR landed as https://github.com/eugeneo/node/commit/2296b677fb1e2ea71e86a899b028ba9e817e86ad. |
This reverts commit 2296b67. That commit was landed without a green CI and is failing on Windows. Ref: nodejs#14460
This reverts commit 2296b67. That commit was landed without a green CI and is failing on Windows. Ref: #14460 PR-URL: #14777 Reviewed-By: Refael Ackermann <[email protected]>
Helper was rewritten to rely on promises instead of manually written
queue and callbacks. This simplifies the code and makes it easier to
maintain and extend.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test: 2 of the inspector tests were rewritten with a new framework.
This is a work in progress. I would be grateful for any feedback before I port other tests on this new helper API.