Skip to content

Conversation

@jonatack
Copy link
Member

@jonatack jonatack commented Apr 15, 2021

This patch improves the cnetaddr link-local test in net_tests by making it platform-specific and by using a higher scoped id value to alleviate recent CI issues.

Closes #21682.

@fanquake fanquake added the Tests label Apr 15, 2021
@practicalswift
Copy link
Contributor

practicalswift commented Apr 15, 2021

The intermittently failing BOOST_CHECK is:

const std::string addr_str{addr.ToString()};
BOOST_CHECK(addr_str == scoped_addr || addr_str == "fe80:0:0:0:0:0:0:1");
// The fallback case "fe80:0:0:0:0:0:0:1" is needed for macOS 10.14/10.15 and (probably) later.

I don't understand why we test if ToString() output includes %zone_index: it clearly doesn't on some platforms, so we cannot rely on it anyways. Then why test it? :)

@jonatack
Copy link
Member Author

My understanding when working on this was that Apple might be going in its own direction with this starting with macOS 10.14 but it still seemed worthwhile to test our code on platforms like Linux and Windows where we can.

@jonatack
Copy link
Member Author

(Without the fallback, only the macOS 10.14 CI was failing. So coverage on the other CIs seemed good to have.)

@practicalswift
Copy link
Contributor

My understanding when working on this was that Apple might be going in its own direction with this starting with macOS 10.14 but it still seemed worthwhile to test our code on platforms like Linux and Windows where we can.

But the test is not conditional on platform, so AFAICT we're testing that ToString either contains %zone_id (the addr_str == scoped_addr case) or that it doesn't contain %zone_id (the addr_str == "fe80:0:0:0:0:0:0:1" case)? :)

const std::string addr_str{addr.ToString()};
BOOST_CHECK(addr_str == scoped_addr || addr_str == "fe80:0:0:0:0:0:0:1");
// The fallback case "fe80:0:0:0:0:0:0:1" is needed for macOS 10.14/10.15 and (probably) later.

In other words: we're effectively not testing anything meaningful in a test that is intermittently failing, no? :)

If so, why not simply remove it? :)

@jonatack
Copy link
Member Author

If you test only the fallback, I found that the change fails on all CIs except the macOS 10.14 one:

-    BOOST_CHECK(addr_str == scoped_addr || addr_str == "fe80:0:0:0:0:0:0:1");
+    BOOST_CHECK(addr_str == "fe80:0:0:0:0:0:0:1");

$ src/test/test_bitcoin -t net_tests
Running 14 test cases...
test/net_tests.cpp(311): error: in "net_tests/cnetaddr_basic": check addr_str == "fe80:0:0:0:0:0:0:1" has failed

*** 1 failure is detected in the test module "Bitcoin Core Test Suite"

@maflcko
Copy link
Member

maflcko commented Apr 15, 2021

Does this actually fix the issue or make it only less likely?

@jonatack
Copy link
Member Author

jonatack commented Apr 15, 2021

As far as I know, the issue began appearing in the CI only this week, so it may be from some recent change in the CI setup, as the tested value of 32 wasn't very high. The CI is green here, so re-pushing now with a very high value (4096). If that causes a failure down the line, I guess we could drop the coverage as suggested above.

@jonatack jonatack force-pushed the cnetaddr-link-local-test branch from 03c7b16 to edb6ac7 Compare April 15, 2021 09:00
@practicalswift
Copy link
Contributor

practicalswift commented Apr 15, 2021

@jonatack

I didn't get if you agree with my statement that the intermittently failing BOOST_CHECK is basically doing:

BOOST_CHECK(to_string_does_contain_zone_id || to_string_does_not_contain_zone_id);

And if so, is there any point in keeping it around? :)


FWIW, patch against current master to show the issue more clearly:

diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index 8eab26f3d..e7c3475ef 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -308,8 +308,9 @@ BOOST_AUTO_TEST_CASE(cnetaddr_basic)
     BOOST_REQUIRE(addr.IsIPv6());
     BOOST_CHECK(!addr.IsBindAny());
     const std::string addr_str{addr.ToString()};
-    BOOST_CHECK(addr_str == scoped_addr || addr_str == "fe80:0:0:0:0:0:0:1");
-    // The fallback case "fe80:0:0:0:0:0:0:1" is needed for macOS 10.14/10.15 and (probably) later.
+    const bool to_string_does_contain_zone_id = addr_str == scoped_addr;
+    const bool to_string_does_not_contain_zone_id = addr_str == "fe80:0:0:0:0:0:0:1";
+    BOOST_CHECK(to_string_does_contain_zone_id || to_string_does_not_contain_zone_id);
     // Test that the delimiter "%" and default zone id of 0 can be omitted for the default scope.
     BOOST_REQUIRE(LookupHost(link_local + "%0", addr, false));
     BOOST_REQUIRE(addr.IsValid());

@jonatack
Copy link
Member Author

jonatack commented Apr 15, 2021

@practicalswift It looks like I should document the test better to communicate the context and information. I'll propose that separately. Edit: and trying testing by platform to address your concerns.

@fanquake
Copy link
Member

It looks like I should document the test better to communicate the context and information. I'll propose that separately.

Why can't that be done as part of this change?

@jonatack
Copy link
Member Author

jonatack commented Apr 15, 2021

Ok. The CI has been green, and #21696 showed that macOS remains the only CI that fails the scoped_addr case.

Let's try (a) improving the documentation and (b) testing scoped_addr by platform.

Edit: will update to BOOST_CHECK_EQUAL if this works.

@jonatack jonatack force-pushed the cnetaddr-link-local-test branch 2 times, most recently from 34b5790 to 0be8e8c Compare April 15, 2021 15:55
@jonatack
Copy link
Member Author

Great--the per-platform scoped address test is green along with the previous two CI runs. Pushing an updated version with BOOST_CHECK( == ) replaced by BOOST_CHECK_EQUAL( , ) for a 4th CI run. I hope this addresses the feedback above while maintaining coverage and adding clarity and context.

@jonatack jonatack force-pushed the cnetaddr-link-local-test branch from 0be8e8c to 9005fb5 Compare April 15, 2021 18:50
@jonatack jonatack changed the title test: use higher value in cnetaddr_basic link-local test test: use higher value and per-platform assert in cnetaddr link-local test Apr 15, 2021
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 15, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@maflcko
Copy link
Member

maflcko commented Apr 17, 2021

Needs rebase after #21689 (comment)

@jonatack
Copy link
Member Author

jonatack commented Apr 17, 2021

If so, why not simply remove it? :)

I think it is better to improve the test and contextual information it provides and I spent time in a way that I thought was constructive and helpful re-verifying and working to do that. Unfortunately, it's an order of magnitude more work to refute statements like "not very meaningful" in the #21689 PR title and the comment above, than it is to say them and just erase coverage and (I think) valuable context.

@jonatack jonatack force-pushed the cnetaddr-link-local-test branch from 9005fb5 to 6ab76c0 Compare April 17, 2021 11:04
@jonatack
Copy link
Member Author

Rebased, added 6b0e879 for context since this change is not adding a test but hopefully improving it.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a reference that 4096 is guaranteed to be unused or is this something that depends on the operating system and the programs currently running?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. From what I understand, the scope ids / zone indices depend on the number of local network interfaces when there are multiple on a single link-local address. Whereas many machines may have the first 8 or 16 decimal integer scope ids in use, the previous test value of 32 seems to be on the high end of the range. I'm not aware of one that is guaranteed to be free, but a value in the thousands (or tens of thousands) might be reasonably worth trying.

Resources:

@jonatack
Copy link
Member Author

@practicalswift does this now address your feedback?

@practicalswift
Copy link
Contributor

@practicalswift does this now address your feedback?

The BOOST_CHECK(to_string_does_contain_zone_id || to_string_does_not_contain_zone_id) issue has been addressed.

I think the issue @MarcoFalke raised about the test outcome being dependent on the user's local configuration remains unfortunately.

Comment on lines +310 to +317
const std::string addr_str{addr.ToString()};
#ifdef MAC_OSX
// Expect macOS to return the address in this format, without zone ids.
BOOST_CHECK_EQUAL(addr_str, "fe80:0:0:0:0:0:0:1");
#else
// Expect normal scoped address functionality on the other platforms.
BOOST_CHECK_EQUAL(addr_str, scoped_addr);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const std::string addr_str{addr.ToString()};
#ifdef MAC_OSX
// Expect macOS to return the address in this format, without zone ids.
BOOST_CHECK_EQUAL(addr_str, "fe80:0:0:0:0:0:0:1");
#else
// Expect normal scoped address functionality on the other platforms.
BOOST_CHECK_EQUAL(addr_str, scoped_addr);
#endif
BOOST_CHECK(addr.ToString().starts_with("fe80:0:0:0:0:0:0:1"));

Maybe just check the prefix if the suffix is unstable?

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 suffix is stable but if the first few scope ids are in use locally then they will be another string and not share the same prefix.

@jonatack
Copy link
Member Author

This test and informational context involved some trial and error and time to obtain, and I think it's a shame to throw out the coverage and information, particularly as it seems to be not well-known info and I tried to provide context about that. However, it seems like I'm swimming upstream to provide this coverage and information.

@jonatack
Copy link
Member Author

The scoped id/zone indices functionality appears to have been dropped entirely by #21756.

@jonatack
Copy link
Member Author

The Up for grabs label on this pull can be removed following the merge of #21985.

@bitcoin bitcoin locked and limited conversation to collaborators Dec 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

6 participants