Skip to content
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

Merged
merged 0 commits into from
Aug 10, 2017
Merged

test: rewrite inspector test helper #14460

merged 0 commits into from
Aug 10, 2017

Conversation

eugeneo
Copy link
Contributor

@eugeneo eugeneo commented Jul 24, 2017

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected 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.

@nodejs-github-bot nodejs-github-bot added dont-land-on-v4.x inspector Issues and PRs related to the V8 inspector protocol test Issues and PRs related to the tests. labels Jul 24, 2017
@eugeneo
Copy link
Contributor Author

eugeneo commented Jul 26, 2017

Newer helper uses port 0 by default. Also it should now be possible to run multiple children processes (no test uses this yet).

@TimothyGu
Copy link
Member

Very nice! I've implemented something like this but for inspector.Session in my VM context PR so I've got a couple suggestions. I'm on my phone though so will post them later.

@eugeneo
Copy link
Contributor Author

eugeneo commented Jul 28, 2017

@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.

@TimothyGu TimothyGu self-assigned this Jul 31, 2017
return { length: bodyOffset + dataLen, message };
}

function promiseWithTimeout(promise, message, multiplicator) {
Copy link
Member

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)

Copy link
Contributor Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrow functions are preferred.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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}))`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting

Copy link
Contributor Author

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.isArray

Copy link
Contributor Author

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is enqueue_ defined?

Copy link
Contributor Author

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) {
Copy link
Member

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?

Copy link
Contributor Author

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);
});
Copy link
Member

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()

Copy link
Contributor Author

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) => {
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@eugeneo
Copy link
Contributor Author

eugeneo commented Jul 31, 2017

@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.

@@ -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) {
Copy link
Member

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

Copy link
Contributor Author

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.

@@ -812,7 +812,49 @@ function restoreWritable(name) {
delete process[name].writeTimes;
}

function onResolvedOrRejected(promise, callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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...

Copy link
Member

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.

@eugeneo
Copy link
Contributor Author

eugeneo commented Aug 3, 2017

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.

Copy link
Member

@TimothyGu TimothyGu left a 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging console.logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed :)

@eugeneo
Copy link
Contributor Author

eugeneo commented Aug 9, 2017

Performed a rebase. New CI: https://ci.nodejs.org/job/node-test-pull-request/9578/

@eugeneo
Copy link
Contributor Author

eugeneo commented Aug 10, 2017

Apparently, last CI run was cancelled. New CI: https://ci.nodejs.org/job/node-test-pull-request/9603/

@eugeneo eugeneo closed this Aug 10, 2017
@eugeneo eugeneo deleted the promisify-test branch August 10, 2017 23:36
@eugeneo
Copy link
Contributor Author

eugeneo commented Aug 10, 2017

CI did not show any relevant failures. This PR landed as https://github.com/eugeneo/node/commit/2296b677fb1e2ea71e86a899b028ba9e817e86ad.

@eugeneo eugeneo merged commit 2296b67 into nodejs:master Aug 10, 2017
addaleax added a commit to addaleax/node that referenced this pull request Aug 11, 2017
This reverts commit 2296b67.

That commit was landed without a green CI and is failing on Windows.

Ref: nodejs#14460
@addaleax
Copy link
Member

@eugeneo The last CI run linked here is for a different PR, this patch makes CI fail on Windows; revert is in #14777

addaleax added a commit that referenced this pull request Aug 11, 2017
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inspector Issues and PRs related to the V8 inspector protocol test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants