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: fix hijackStdout behavior in console #14647

Closed
wants to merge 3 commits into from

Conversation

XadillaX
Copy link
Contributor

@XadillaX XadillaX commented Aug 6, 2017

console.log and some other function will swallow the exception in stdout.write. So an asynchronous exception is needed, or common.hijackStdout won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

Checklist
  • make -j4 test
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Aug 6, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87
@XadillaX
Copy link
Contributor Author

XadillaX commented Aug 7, 2017

/cc @nodejs/testing

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

1 CR
2 nits

try {
listener(data);
} catch(e) {
process.nextTick(function() {
Copy link
Contributor

@refack refack Aug 9, 2017

Choose a reason for hiding this comment

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

Nit: I know you like functions but this could be a single line.
IMHO the indentation is weird

});

let uncaughtTimes = 0;
process.on('uncaughtException', common.mustCallAtLeast(function(e) {
Copy link
Contributor

@refack refack Aug 9, 2017

Choose a reason for hiding this comment

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

CR: How is the mustCallAtLeast fit with the ${([ 'err', 'out' ])[uncaughtTimes++]} trick?

Copy link
Contributor Author

@XadillaX XadillaX Aug 10, 2017

Choose a reason for hiding this comment

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

The second parameter of common.mustCallAtLeast is 2.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I wasn't clear. I meant it should be mustCall, as any more calls would generate console undefined error


// hijackStderr and hijackStdout again
// for console
[ 'err', 'out' ].forEach((txt) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: do [['err', 'error'], ['out', 'log']].forEach(([ext, method]) => {
instead of console[txt === 'err' ? 'error' : 'log']('test');

@XadillaX
Copy link
Contributor Author

@refack updated.

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

LGTM. Just need to replace mustCallAtLeast with mustCall

});

let uncaughtTimes = 0;
process.on('uncaughtException', common.mustCallAtLeast(function(e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I wasn't clear. I meant it should be mustCall, as any more calls would generate console undefined error

@XadillaX
Copy link
Contributor Author

@refack How about now? I've added the code:

assert.strictEqual(uncaughtTimes < 2, true);

@refack
Copy link
Contributor

refack commented Aug 11, 2017

@refack How about now? I've added the code:

assert.strictEqual(uncaughtTimes < 2, true);

That works too.

CI: https://ci.nodejs.org/job/node-test-pull-request/9617/

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

jasnell pushed a commit that referenced this pull request Aug 29, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

PR-URL: #14647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

Landed in 1ffd01c

@jasnell jasnell closed this Aug 29, 2017
ghost pushed a commit to ayojs/ayo that referenced this pull request Aug 30, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

PR-URL: nodejs/node#14647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
ghost pushed a commit to ayojs/ayo that referenced this pull request Aug 30, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

PR-URL: nodejs/node#14647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
cjihrig pushed a commit to cjihrig/node that referenced this pull request Aug 31, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

PR-URL: nodejs#14647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request Sep 10, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

PR-URL: #14647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Sep 10, 2017
MylesBorins pushed a commit that referenced this pull request Sep 12, 2017
`console.log` and some other function will swallow the exception in
`stdout.write`. So an asynchronous exception is needed, or
`common.hijackStdout` won't detect some exception.

Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87

PR-URL: #14647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@MylesBorins
Copy link
Contributor

it looks like this is a patch to test features that don't exist on v6.x

Should we backport them?

@MylesBorins
Copy link
Contributor

ping

@MylesBorins
Copy link
Contributor

ping @XadillaX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants