-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
thanks, now you are at it, will you please accommodate AIX as well in the |
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.
The substantive additions at the bottom of the test file look good to me. Would be good to remove the unrelated style/formatting changes.
test/parallel/test-os.js
Outdated
@@ -20,15 +20,16 @@ | |||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
|
|||
'use strict'; | |||
|
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.
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.
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.
Alright, I will change it back. I am still learning nodejs guides though
test/parallel/test-os.js
Outdated
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)), |
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.
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.
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.
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
test/parallel/test-os.js
Outdated
@@ -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) { |
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.
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.
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.
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?
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.
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.
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 don't think we will get consensus on that
@tniessen you are probably right.
Sure I will remove them
@gireeshpunathil I will definitely need it |
I see 2 patterns in AIX:
Pattern 1:
Pattern 2:
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:
|
@gireeshpunathil got it |
@gireeshpunathil are you sure about |
yes, here is a portion of os.networkInterfaces() output:
|
@gireeshpunathil check out |
comments have been addressed, dismissing my review, thanks
@kuroljov - thanks. While I was validating your code in AIX, it revealed a new issue - the 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. |
@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. |
@nodejs/testing |
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.
2 tiny nits
test/parallel/test-os.js
Outdated
@@ -139,9 +162,13 @@ switch (platform) { | |||
const EOL = os.EOL; | |||
assert.ok(EOL.length > 0); |
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.
Now this could be removed
test/parallel/test-os.js
Outdated
[`${os.endianness}`, os.endianness()], | ||
[`${os.tmpdir}`, os.tmpdir()], | ||
[`${os.arch}`, os.arch()], | ||
[`${os.platform}`, os.platform()] | ||
].forEach((set) => assert.strictEqual(set[0], set[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.
tiny nit: .forEach(([expected, actual]) => assert.strictEqual(expected, actual));
Regarding the AIX fail, you can edit [$system==aix]
test-os.js: : PASS,FLAKY And we can land this now |
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.
LGTM
New CI: https://ci.nodejs.org/job/node-test-pull-request/9041/ 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)
... |
From last run same error on [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.
https://ci.nodejs.org/job/node-test-commit-arm/10771/nodes=ubuntu1604-arm64/ |
test/parallel/test-os.js
Outdated
[ | ||
[+os.freemem, os.freemem()], |
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.
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`));
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.
@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
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.
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.
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 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.
I've lost an access to my working pc and got back it just now. Sorry for that. I will push changes soon |
Ping @kuroljov |
Yeah I am sorry. I remember everything and I will finish this PR until 16.09 |
It has been 583 commits since my last push here. Fascinating 👍 |
We call that a slow Tuesday in this repository. Also, this needs a rebase. |
Statements from 82% to 94.12% Functions from 66.67% to 100%
Remove it because after 2 months it was implemented actually. Started with this PR though
Replaced to + and string templates. Completely forgot about them last time |
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.
LGTM
Left a few comments
@@ -18,4 +18,3 @@ test-npm-install: PASS,FLAKY | |||
[$system==solaris] # Also applies to SmartOS | |||
|
|||
[$system==freebsd] | |||
|
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 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 |
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.
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; | ||
} |
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.
Should add a default
:
default:
common.printSkipMessage(`Skipping assertion of 'os.networkInterfaces()' on ${platform}`);
break;
assert.ok(/^\d+\.\d+$/.test(release)); | ||
} |
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 is a unrelated change and should be reverted.
Landed in ea9322168cb7042ffb83669ab2934b006af10221 I addressed all the comments while landing. |
Arg, I made a mistake here and removed the landed commit again. Reopening. |
PR-URL: #14098 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in 22f95e7 |
@kuroljov Thanks! |
PR-URL: #14098 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
PR-URL: #14098 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
PR-URL: nodejs/node#14098 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
PR-URL: #14098 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
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 |
Basically added tests for
Symbol.toPrimitive
casesI think it is actually a 100% because some statements/branches are
platform
dependentNB Obviously I ran tests, but seems like
master
branch has some tests failing in other modules.os
module not failing thoughChecklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test