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: split up and refactor test-domain #13614

Closed
wants to merge 1 commit into from

Conversation

addaleax
Copy link
Member

Split up test-domain into multiple, more focused test files and use more modern JS inside of them.
/cc @nodejs/testing

@addaleax addaleax added domain Issues and PRs related to the domain subsystem. test Issues and PRs related to the tests. labels Jun 11, 2017
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Jun 11, 2017
@refack
Copy link
Contributor

refack commented Jun 11, 2017

I'm a bit ambivalent about this 🤔
Pros:

  1. more focused tests => better error => easier tracing
  2. readability
  3. better use of common and modern syntax

Cons

  1. I like that in test-domain it's all handled by the same Domain object
  2. [42, null, undefined, false, () => {}, 'string'].forEach(function(something) was nice
  3. multiple tests => multiple node bootstrapping (~1s each)
  4. duplication of setup code

Bottom line

Maybe add another test that asserts that a single domain can handle multiple error events and multiple values?

@addaleax
Copy link
Member Author

Maybe add another test that asserts that a single domain can handle multiple error events and multiple values?

Fwiw I added a vaiant of the error-types test that throws all errors inside the same domain.

@Trott
Copy link
Member

Trott commented Jun 11, 2017

Pros:

One more for the pro list: Reduced likelihood of side effects between tests.

I'm definitely +1 on this.

Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

LGTM

@Trott
Copy link
Member

Trott commented Jun 11, 2017

/cc @misterdjules

Copy link

@misterdjules misterdjules left a comment

Choose a reason for hiding this comment

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

This generally looks good to me. I like the idea of splitting the tests in separate files, so thanks for doing that!

In general, I'd like it if we kept, or improved on, the existing comments. They help people unfamiliar with the code base to understand the tests' purpose, behavior and internals.

I left a few questions as well. For instance, it seems that a test might have been lost in the transition, but I may have missed something too.

{
const d = new domain.Domain();

const bound = d.intercept(common.mustCall((data) => {

Choose a reason for hiding this comment

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

Instead of removing them, keeping (or improving on) the comments present in the previous version of this test would help understand it.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem I see with the previous comments regarding this test (and some of the others) is that they seemed more like API documentation rather than actually helping to explain what the test does. In this case, I hope it becomes much more visible what each part of the test does by identifying the groups of code that test a single piece of the functionality.

Choose a reason for hiding this comment

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

Some of these comments describe the intention of these tests. For instance:

// catch thrown errors no matter how many times we enter the event loop [...]

Looking at the new version of that test in test-domain-implicit-binding.js, it's not clear why the error is thrown from a nested async operation nested several layers deep, and so it's not clear to the person who hasn't written this test whether it even makes sense to keep this test.

I still think it would be worth it to keep those comments.

@@ -0,0 +1,23 @@
'use strict';

Choose a reason for hiding this comment

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

What is the difference between this test and test/parallel/test-domain-error-types.js?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only difference is that one of the tests emits the errors on the same domain object, because that was requested here. I’ve added comments referencing the other test file in each of them.

Choose a reason for hiding this comment

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

Great, thanks!


const d = new domain.Domain();

assert.strictEqual(d.run(() => 'return value'),

Choose a reason for hiding this comment

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

Here too, keeping or improving on the comments of the previous version of this test would help understand its purpose.

// this only uses implicit binding, except for the first function
// passed to d.run(). The rest are implicitly bound by virtue of being
// set up while in the scope of the d domain.
d.run(function() {

Choose a reason for hiding this comment

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

Was this test removed by this change, if so, why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that was an oversight. I added it as test-domain-implicit-binding.js.

Choose a reason for hiding this comment

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

Excellent, thank you!

@addaleax addaleax force-pushed the test-domain-refactor branch 2 times, most recently from 0655c38 to 3ccee05 Compare June 16, 2017 13:42
@addaleax
Copy link
Member Author

@addaleax
Copy link
Member Author

Does anybody mind if I land this next-week-ish?

@BridgeAR
Copy link
Member

This needs a rebase. Otherwise I think this could land as it.

@BridgeAR BridgeAR dismissed misterdjules’s stale review August 30, 2017 22:07

The comments were addressed as far as I see it. There was no response for a long time. Please have another look.

@BridgeAR
Copy link
Member

BridgeAR commented Sep 8, 2017

Ping @addaleax

@BridgeAR BridgeAR added the stalled Issues and PRs that are stalled. label Sep 8, 2017
@BridgeAR
Copy link
Member

Ping @addaleax once more

@addaleax
Copy link
Member Author

@jasnell
Copy link
Member

jasnell commented Sep 29, 2017

Trying CI again on windows: https://ci.nodejs.org/job/node-test-commit-windows-fanned/12048/

@BridgeAR
Copy link
Member

BridgeAR commented Oct 2, 2017

@addaleax seems like there are related failures.

https://ci.nodejs.org/job/node-test-binary-windows/11454/COMPILED_BY=vcbt2015,RUNNER=win10,RUN_SUBSET=2/console

not ok 99 parallel/test-domain-fs-enoent-stream
  ---
  duration_ms: 0.155
  severity: fail
  stack: |-
    assert.js:44
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 'ENOENT: no such file or directory, open \'c:\\workspace\\node-test-binary-windows\\COMPILED_BY\\vs2017\\RUNNER\\win2016\\RUN_SU === 'ENOENT: no such file or directory, open \'stream for nonexistent file\''
        at Domain.d.on.common.mustCall (c:\workspace\node-test-binary-windows\COMPILED_BY\vs2017\RUNNER\win2016\RUN_SUBSET\2\test\parallel\test-domain-fs-enoent-stream.js:13:10)
        at Domain.<anonymous> (c:\workspace\node-test-binary-windows\COMPILED_BY\vs2017\RUNNER\win2016\RUN_SUBSET\2\test\common\index.js:517:15)
        at emitOne (events.js:115:13)
        at Domain.emit (events.js:210:7)
        at ReadStream.emit (events.js:180:14)
        at fs.js:2025:12
        at FSReqWrap.oncomplete (fs.js:138:15)

@addaleax
Copy link
Member Author

addaleax commented Oct 7, 2017

Rebased, new CI to see whether errors persist:

CI: https://ci.nodejs.org/job/node-test-commit/12858/

@refack
Copy link
Contributor

refack commented Oct 7, 2017

All windows machines returned:

not ok 113 parallel/test-domain-fs-enoent-stream
  ---
  duration_ms: 0.143
  severity: fail
  stack: |-
    assert.js:45
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 'ENOENT: no such file or directory, open \'c:\\workspace\\node-test-binary-windows\\COMPILED_BY\\vcbt2015\\RUNNER\\win10\\RUN_SU === 'ENOENT: no such file or directory, open \'stream for nonexistent file\''
        at Domain.d.on.common.mustCall (c:\workspace\node-test-binary-windows\COMPILED_BY\vcbt2015\RUNNER\win10\RUN_SUBSET\3\test\parallel\test-domain-fs-enoent-stream.js:13:10)
        at Domain.<anonymous> (c:\workspace\node-test-binary-windows\COMPILED_BY\vcbt2015\RUNNER\win10\RUN_SUBSET\3\test\common\index.js:517:15)
        at emitOne (events.js:115:13)
        at Domain.emit (events.js:210:7)
        at ReadStream.emit (events.js:180:14)
        at fs.js:2028:12
        at FSReqWrap.oncomplete (fs.js:139:15)
  ...

P.S. Seems like the wWindows fs error has a full path.

Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.
@addaleax
Copy link
Member Author

Okay, I’ve relaxed the error message a bit. This is not an fs test anyway.

CI: https://ci.nodejs.org/job/node-test-commit/13060/

@addaleax addaleax removed the stalled Issues and PRs that are stalled. label Oct 16, 2017
@addaleax
Copy link
Member Author

Landed in 1a2f579

@addaleax addaleax closed this Oct 16, 2017
@addaleax addaleax deleted the test-domain-refactor branch October 16, 2017 09:30
addaleax added a commit that referenced this pull request Oct 16, 2017
Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.

PR-URL: #13614
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this pull request Oct 18, 2017
Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.

PR-URL: #13614
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
addaleax added a commit to ayojs/ayo that referenced this pull request Oct 18, 2017
Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.

PR-URL: nodejs/node#13614
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 16, 2017
Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.

PR-URL: #13614
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Nov 21, 2017
MylesBorins pushed a commit that referenced this pull request Nov 21, 2017
Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.

PR-URL: #13614
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 28, 2017
Split up test-domain into multiple, more focused test files
and use more modern JS inside of them.

PR-URL: #13614
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain Issues and PRs related to the domain subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants