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: improve check in test-os #14655

Closed
wants to merge 1 commit into from
Closed

test: improve check in test-os #14655

wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Aug 7, 2017

The check for os.networkInterfaces() in test-os.js may be too
strict. It's apparently possible for a machine to be configured with
multiple IPv4 loopback interfaces. Increase specificity of filter to
check on only the object we expect.

Fixes: #14654

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test os

@Trott Trott added os Issues and PRs related to the os subsystem. test Issues and PRs related to the tests. labels Aug 7, 2017
@Trott Trott changed the title test: relax check in test-os test: improve check in test-os Aug 7, 2017
@Trott
Copy link
Member Author

Trott commented Aug 7, 2017

@@ -116,8 +116,8 @@ const interfaces = os.networkInterfaces();
switch (platform) {
case 'linux':
{
const filter = (e) => e.address === '127.0.0.1';
const actual = interfaces.lo.filter(filter);
const fltr = (e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0';

Choose a reason for hiding this comment

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

Not a big deal but FWIW, the fltr const name is now inconsistent with the filter used in the win32 case

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you leave the name as filter and just break the line on the && operator.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cjihrig Sure, done.

@@ -116,8 +116,8 @@ const interfaces = os.networkInterfaces();
switch (platform) {
case 'linux':
{
const filter = (e) => e.address === '127.0.0.1';
const actual = interfaces.lo.filter(filter);
const fltr = (e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you leave the name as filter and just break the line on the && operator.

The check for `os.networkInterfaces()` in `test-os.js` may be too
strict. It's apparently possible for a machine to be configured with
multiple IPv4 loopback interfaces. Increase specificity of filter to
check on only the object we expect.

Fixes: nodejs#14654
@@ -116,7 +116,8 @@ const interfaces = os.networkInterfaces();
switch (platform) {
case 'linux':
{
const filter = (e) => e.address === '127.0.0.1';
const filter =
(e) => e.address === '127.0.0.1' && e.netmask === '255.0.0.0';
const actual = interfaces.lo.filter(filter);
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
Copy link
Contributor

Choose a reason for hiding this comment

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

[warning 🚨 scope-creep]
AFAICT expected and the asserting could be hoisted, and switch replaced with if or trinary for selecting interfaces.lo / interfaces['Loopback Pseudo-Interface 1']

Copy link
Member Author

Choose a reason for hiding this comment

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

Some reasons to maybe not do that:

  • If we want to add macOS to the switch statement (in another PR), it will have a different expected value. (The MAC address is different. Yes, the MAC address is different on Mac. Ha ha, ha ha, gosh, I'm funny.)

  • Probably don't want to replace the switch because we need a do-nothing default for macos, smartos... A switch makes sense here, I think. I mean, you can make it work with an if, of course. But I think this more verbose code is actually more readable even though it does violate DRY. (I often don't value DRY much in tests, TBH.)

Even if I'm wrong about that evaluation... must...resist....scope creep.

@refack
Copy link
Contributor

refack commented Aug 8, 2017

👍

(The MAC address is different. Yes, the MAC address is different on Mac. Ha ha, ha ha, gosh, I'm funny.)

Apple SMH...

@Trott
Copy link
Member Author

Trott commented Aug 10, 2017

Landed in 2923ed1

@Trott Trott closed this Aug 10, 2017
Trott added a commit to Trott/io.js that referenced this pull request Aug 10, 2017
The check for `os.networkInterfaces()` in `test-os.js` may be too
strict. It's apparently possible for a machine to be configured with
multiple IPv4 loopback interfaces. Increase specificity of filter to
check on only the object we expect.

PR-URL: nodejs#14655
Fixes: nodejs#14654
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit that referenced this pull request Aug 10, 2017
The check for `os.networkInterfaces()` in `test-os.js` may be too
strict. It's apparently possible for a machine to be configured with
multiple IPv4 loopback interfaces. Increase specificity of filter to
check on only the object we expect.

PR-URL: #14655
Fixes: #14654
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax addaleax mentioned this pull request Aug 13, 2017
MylesBorins pushed a commit that referenced this pull request Sep 19, 2017
The check for `os.networkInterfaces()` in `test-os.js` may be too
strict. It's apparently possible for a machine to be configured with
multiple IPv4 loopback interfaces. Increase specificity of filter to
check on only the object we expect.

PR-URL: #14655
Fixes: #14654
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Sep 20, 2017
@Trott Trott deleted the relax-os branch January 13, 2022 22:46
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.

nodejs Makefile:196: recipe for target 'test' failed make: *** [test] Error 1
8 participants