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: increase test coverage for os.js #14098

Closed
wants to merge 6 commits into from
Closed

test: increase test coverage for os.js #14098

wants to merge 6 commits into from

Conversation

viktor-ku
Copy link
Contributor

@viktor-ku viktor-ku commented Jul 6, 2017

Basically added tests for Symbol.toPrimitive cases

  • Statements from 82% to 94.12%
    I think it is actually a 100% because some statements/branches are platform dependent
  • Functions from 66.67% to 100%

NB Obviously I ran tests, but seems like master branch has some tests failing in other modules. os module not failing though

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • 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 Jul 6, 2017
@gireeshpunathil
Copy link
Member

thanks, now you are at it, will you please accommodate AIX as well in the os.networkInterfaces(); section (Currently covering win and linux only)? If you don't have access to an AIX box, please let me know, I shall provide the format in which AIX output appears for this call.

@mscdex mscdex added the os Issues and PRs related to the os subsystem. label Jul 6, 2017
Trott
Trott previously requested changes Jul 6, 2017
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.

The substantive additions at the bottom of the test file look good to me. Would be good to remove the unrelated style/formatting changes.

@@ -20,15 +20,16 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

Copy link
Member

Choose a reason for hiding this comment

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

See https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md for our general guidelines on test style. The import of the common module should be on the line immediately after use strict. Inserting a blank line between common and the next module would be good, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I will change it back. I am still learning nodejs guides though

array: (value) => { assert.ok(Array.isArray(value)); },
string: (value) => assert.strictEqual(typeof value, 'string'),
number: (value) => assert.strictEqual(typeof value, 'number'),
array: (value) => assert.ok(Array.isArray(value)),
Copy link
Member

Choose a reason for hiding this comment

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

Removing the braces here changes the function to return a value. It doesn't matter in this case, but by returning a value, the code implies the return value is significant. Moreover, this is an unrelated change from increasing code coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the braces here changes the function to return a value. It doesn't matter in this case, but by returning a value, the code implies the return value is significant

Right, I have never thought that way

@@ -93,8 +94,9 @@ const release = os.release();
is.string(release);
assert.ok(release.length > 0);
//TODO: Check format on more than just AIX
if (common.isAix)
if (common.isAix) {
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated change. Our code base has many examples of both including and omitting braces in this type of situation. Probably best not to add this just so the next person can remove it etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is still a little confusing to me because it is not obvious when to add braces and when not to. I have seen conditions with one line of code after it being with and without braces. Maybe we need to use some eslint rule so it will yell at us on some cases?

Copy link
Member

Choose a reason for hiding this comment

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

The only rule we currently have is to use braces when the contained statement is more than one line. I don't think it is necessary to enforce either behavior when braces are optional, but if it does not churn too much, we might as well lint it, even though I don't think we will get consensus on that.

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 don't think we will get consensus on that

@tniessen you are probably right.

Sure I will remove them

@viktor-ku
Copy link
Contributor Author

If you don't have access to an AIX box, please let me know, I shall provide the format in which AIX output appears for this call

@gireeshpunathil I will definitely need it

@gireeshpunathil
Copy link
Member

I see 2 patterns in AIX:

  1. Loopback interface configured, in which case it goes under lo0[0]
  2. Loopback interface not configured. In which case only Ethernet entries are retrieved.

Pattern 1:

{ en0: 
   [ { address: 'X.X.X.X',
       netmask: 'Y.Y.Y.Y',
       family: 'IPv4',
       mac: '00:00:00:00:00:00',
       internal: false } ],
  lo0: 
   [ { address: '127.0.0.1',
       netmask: '0.0.0.1',
       family: 'IPv4',
       mac: 'xx:xx:xx:xx:xx:xx',
       internal: true },
     { address: '::1',
       netmask: '::700:0:205b:ea9',
       family: 'IPv6',
       mac: '00:00:00:01:10:bc',
       scopeid: 1,
       internal: true } ] }

Pattern 2:

{ en0: 
   [ { address: 'X.X.X.X',
       netmask: '0.0.0.0',
       family: 'IPv4',
       mac: '00:00:00:00:00:00',
       internal: false } ] }

Also I see one deviation from Linux: MAC address is non-zero on the loopback interface.

So the test logic may be on the lines of:

  1. Retrieve the object
  2. Check whether interfaces["lo0"] exists or not
  3. If yes:
    a. extract interfaces["lo0"][0] as the loopback entry.
    b. nullify the mac field in the actual as well as the expected (as we cannot make a meaningful comparison here)
    c. make comparison
  4. If no, skip.

@viktor-ku
Copy link
Contributor Author

@gireeshpunathil got it

@viktor-ku
Copy link
Contributor Author

@gireeshpunathil are you sure about lo0 IPv4 netmask being 0.0.0.1 and not 255.0.0.0?

@gireeshpunathil
Copy link
Member

yes, here is a portion of os.networkInterfaces() output:

  lo0: 
   [ { address: '127.0.0.1',
       netmask: '0.0.0.1',
       family: 'IPv4',

@viktor-ku
Copy link
Contributor Author

@gireeshpunathil check out

@Trott Trott dismissed their stale review July 6, 2017 16:00

comments have been addressed, dismissing my review, thanks

@gireeshpunathil
Copy link
Member

@kuroljov - thanks. While I was validating your code in AIX, it revealed a new issue - the os.networkInterfaces() seem to be producing inconsistent results. I have captured this in #14119 .

This would mean you may either (a) hold this PR until #14119 is addressed, (b) go ahead with the PR without the AIX changes. The current changes in AIX will fail in CI. I recommend (a).

Thanks once again, catching the bug early being the essence of test cases, and this PR helped in that.

@viktor-ku
Copy link
Contributor Author

@gireeshpunathil I will wait until someone answers to that issue there. However these AIX changes has nothing with increasing test coverage so I would prefer go without AIX changes but we will see.

@Trott
Copy link
Member

Trott commented Jul 7, 2017

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

2 tiny nits

@@ -139,9 +162,13 @@ switch (platform) {
const EOL = os.EOL;
assert.ok(EOL.length > 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Now this could be removed

[`${os.endianness}`, os.endianness()],
[`${os.tmpdir}`, os.tmpdir()],
[`${os.arch}`, os.arch()],
[`${os.platform}`, os.platform()]
].forEach((set) => assert.strictEqual(set[0], set[1]));
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny nit: .forEach(([expected, actual]) => assert.strictEqual(expected, actual));

@refack
Copy link
Contributor

refack commented Jul 7, 2017

Regarding the AIX fail, you can edit test/parallel/parallel.status and add:

[$system==aix]
test-os.js:                         : PASS,FLAKY

And we can land this now

@refack
Copy link
Contributor

refack commented Jul 7, 2017

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

@refack
Copy link
Contributor

refack commented Jul 8, 2017

New CI: https://ci.nodejs.org/job/node-test-pull-request/9041/
Last one had this error, let's see if it reproduces

not ok 225 parallel/test-os
  ---
  duration_ms: 0.139
  severity: fail
  stack: |-
    assert.js:55
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 2157244416 === 2157236224
        at __dirname.forEach (c:\workspace\node-test-binary-windows\RUN_SUBSET\0\VS_VERSION\vs2015-x86\label\win2008r2\test\parallel\test-os.js:225:27)
        at Array.forEach (<anonymous>)
        at Object.<anonymous> (c:\workspace\node-test-binary-windows\RUN_SUBSET\0\VS_VERSION\vs2015-x86\label\win2008r2\test\parallel\test-os.js:225:3)
        at Module._compile (module.js:569:30)
        at Object.Module._extensions..js (module.js:580:10)
        at Module.load (module.js:503:32)
        at tryModuleLoad (module.js:466:12)
        at Function.Module._load (module.js:458:3)
        at Function.Module.runMain (module.js:605:10)
        at startup (bootstrap_node.js:158:16)
  ...

https://ci.nodejs.org/job/node-test-binary-windows/9697/

@refack
Copy link
Contributor

refack commented Jul 8, 2017

From last run same error on ubuntu1604-arm64,
Probably from one of:

[os.freemem, os.freemem()],
[os.totalmem, os.totalmem()],
[os.uptime, os.uptime()],

Probably need to add tolerance to the values, and change the error message.

not ok 893 parallel/test-os
  ---
  duration_ms: 0.628
  severity: fail
  stack: |-
    assert.js:55
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 129072861184 === 129070764032
        at __dirname.forEach (/home/iojs/build/workspace/node-test-commit-arm/nodes/ubuntu1604-arm64/test/parallel/test-os.js:225:27)
        at Array.forEach (<anonymous>)
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-arm/nodes/ubuntu1604-arm64/test/parallel/test-os.js:225:3)
        at Module._compile (module.js:569:30)
        at Object.Module._extensions..js (module.js:580:10)
        at Module.load (module.js:503:32)
        at tryModuleLoad (module.js:466:12)
        at Function.Module._load (module.js:458:3)
        at Function.Module.runMain (module.js:605:10)
        at startup (bootstrap_node.js:158:16)
  ...

https://ci.nodejs.org/job/node-test-commit-arm/10771/nodes=ubuntu1604-arm64/

[
[+os.freemem, os.freemem()],
Copy link
Contributor

Choose a reason for hiding this comment

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

Idea:
replace all the pairs with just the field name and last line to

].forEach((field) => assert.strictEqual(os[field], os[field](), `os.${field} failed Symbol.toPrimitive test`));

Copy link
Contributor Author

@viktor-ku viktor-ku Sep 14, 2017

Choose a reason for hiding this comment

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

@refack there are sometimes string sometimes number so the check should be more complicated than just os[field]. So I guess it's not worth it and the current assertion is not that bad

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the *mem & uptime can't be compared with strictEqual (the values can change between the two calls), they should be moved to their own loop anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @refack that it would be very good to add the field name as it is difficult to know otherwise from what entry a failure is actually coming from.
This could also be done by either adding a string to each entry you are iterating over as a third entry or by just using the index of the forEach loop as in Entry ${i} failed but I prefer what @refack suggests.

I personally would prefer a third alternative - to just remove the loop altogether as it is unnecessary.
We would even have less lines if we use e.g. assert.strictEqual(${os.endianness}, os.endianness()) directly instead of values from the loop and it would be clear where the error is coming from.

I also do not see any way to compare freemem or uptime without those being flaky. So please remove those two entries again.

@viktor-ku
Copy link
Contributor Author

I've lost an access to my working pc and got back it just now. Sorry for that. I will push changes soon

@BridgeAR
Copy link
Member

Ping @kuroljov

@viktor-ku
Copy link
Contributor Author

Yeah I am sorry. I remember everything and I will finish this PR until 16.09

@viktor-ku
Copy link
Contributor Author

It has been 583 commits since my last push here. Fascinating 👍

@cjihrig
Copy link
Contributor

cjihrig commented Sep 14, 2017

It has been 583 commits since my last push here.

We call that a slow Tuesday in this repository.

Also, this needs a rebase.

@refack
Copy link
Contributor

refack commented Sep 15, 2017

@refack refack self-assigned this Sep 15, 2017
@viktor-ku
Copy link
Contributor Author

Replaced to + and string templates. Completely forgot about them last time

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
Left a few comments

@@ -18,4 +18,3 @@ test-npm-install: PASS,FLAKY
[$system==solaris] # Also applies to SmartOS

[$system==freebsd]

Copy link
Contributor

Choose a reason for hiding this comment

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

This shows two lines at the end of the file (i.e. the file ends in \n\n - one shows up as a new line, and the other as an EOF \n which is required...)


assert.strictEqual(+os.totalmem, os.totalmem());

// At least we can check that these values are numbers
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: change comment to:

// Assert that the following values are coercible to numbers.

family: 'IPv4',
internal: true,
cidr: '127.0.0.1/8'
}];
assert.deepStrictEqual(actual, expected);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add a default:

default:
  common.printSkipMessage(`Skipping assertion of 'os.networkInterfaces()' on ${platform}`);
  break;

@refack
Copy link
Contributor

refack commented Sep 25, 2017

assert.ok(/^\d+\.\d+$/.test(release));
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a unrelated change and should be reverted.

@BridgeAR
Copy link
Member

BridgeAR commented Oct 2, 2017

Landed in ea9322168cb7042ffb83669ab2934b006af10221

I addressed all the comments while landing.

@BridgeAR BridgeAR closed this Oct 2, 2017
@BridgeAR
Copy link
Member

BridgeAR commented Oct 2, 2017

Arg, I made a mistake here and removed the landed commit again. Reopening.

@BridgeAR BridgeAR reopened this Oct 2, 2017
refack pushed a commit that referenced this pull request Oct 2, 2017
PR-URL: #14098
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@refack
Copy link
Contributor

refack commented Oct 2, 2017

Landed in 22f95e7

@refack refack closed this Oct 2, 2017
@refack refack removed their assignment Oct 2, 2017
@refack
Copy link
Contributor

refack commented Oct 2, 2017

@kuroljov Thanks!

MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
PR-URL: #14098
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Oct 3, 2017
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
PR-URL: #14098
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 4, 2017
PR-URL: nodejs/node#14098
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Oct 11, 2017
PR-URL: #14098
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins
Copy link
Contributor

This does not land cleanly in LTS. Please feel free to manually backport by following the guide. Please also feel free to replace do-not-land if it is being backported

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

Successfully merging this pull request may close these issues.