[test] clarify rpc_net & p2p_disconnect_ban functional tests #19877

pull amitiuttarwar wants to merge 2 commits into bitcoin:master from amitiuttarwar:2020-09-rpcnet-fixes changing 2 files +39 −33
  1. amitiuttarwar commented at 8:44 pm on September 4, 2020: contributor

    small improvements to clarify logic in the functional tests

    1. have test logic in rpc_net.py match run order of the test
    2. remove connect_nodes calls that are redundant with the automatic test setup executed by the test framework

    Noticed when I was trying to debug a test for #19725. Small changes but imo very helpful, because they initially confused me.

  2. DrahtBot added the label Tests on Sep 4, 2020
  3. in test/functional/rpc_net.py:98 in 9bd90db7e9 outdated
    93+        assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500"))
    94+        assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000"))
    95+        # check the `servicesnames` field
    96+        for info in peer_info:
    97+            assert_net_servicesnames(int(info[0]["services"], 0x10), info[0]["servicesnames"])
    98+
    


    ipriver commented at 6:48 pm on September 5, 2020:
    Why did you move test_getpeerinfo function declaration 75 lines upwards if you haven’t modified it? It just creates unnecessary diffs for your commit.

    robot-dreams commented at 8:11 pm on September 5, 2020:

    Yeah, reasonable question!

    • If you review one commit at a time, it’s clearer to see what’s going on (there’s a move-only commit followed by a small functionality change)
    • The commit message explains why this function was moved: “Match test order with run order”

    ipriver commented at 8:37 pm on September 5, 2020:
    @robot-dreams Agree, I missed the second commit and its title that describes this change. :blush:

    amitiuttarwar commented at 8:25 pm on September 11, 2020:
    thanks for taking a look :)
  4. robot-dreams commented at 8:15 pm on September 5, 2020: contributor

    Concept ACK, thanks for clarifying! After trying to trace the code, I agree with you that addnode should add connections in both directions.

    • Would it also make sense to change the “Connect nodes both ways” on line 147 below?
    • The wait_for_helper calls in the connect_nodes implementation wait until the node has received a version and a verack. However, it doesn’t wait until the peer has received a verack. Could this introduce some sort of extremely rare race condition?
  5. in test/functional/rpc_net.py:57 in 9bd90db7e9 outdated
    51@@ -52,9 +52,12 @@ def set_test_params(self):
    52     def run_test(self):
    53         # Get out of IBD for the minfeefilter and getpeerinfo tests.
    54         self.nodes[0].generate(101)
    55-        # Connect nodes both ways.
    56+
    57+        # By default, the test framework sets up an addnode connection from
    58+        # node 1 --> node0. By connecting node0 --> node 1, this leaves us with
    


    epson121 commented at 2:58 pm on September 8, 2020:
    nit - By connecting node0 --> node 1, **we're left** with

    amitiuttarwar commented at 8:25 pm on September 11, 2020:
    done
  6. epson121 commented at 5:12 pm on September 8, 2020: none

    Concept ACK

    As @robot-dreams mentioned, these changes could be applied in L147.

    Also, similar behaviour can be seen in tests\functional\p2p_disconnect_ban.py L21 and L80, e.g.

    0    def run_test(self):
    1        self.log.info("Connect nodes both way")
    2        connect_nodes(self.nodes[0], 1)
    3        connect_nodes(self.nodes[1], 0)
    4        ...
    

    so updating code there as well could be an option.

    As a reference, original change was introduced in this PR: https://github.com/bitcoin/bitcoin/pull/16898/files

  7. amitiuttarwar force-pushed on Sep 11, 2020
  8. amitiuttarwar commented at 8:22 pm on September 11, 2020: contributor

    thanks for the reviews @ipriver, @robot-dreams & @epson121 ! updated to improve another “connect nodes both ways” instance in p2p_disconnect_ban.py PR is ready for review!

    thoughts around review suggestions / questions :

    Would it also make sense to change the “Connect nodes both ways” on line 147 below?

    good suggestion but I’ve looked into it & have found that those connections are important to leave in. Here is why: at the start of the test, the test framework creates the initial node connection behind the scenes, so we only need one additional connect_nodes call to get a two way connection. However in test_getnetworkinfo it sets the networkactive flag to false, which disconnects everything. So, we need to explicitly connect_nodes both ways in order to restore the two way connection between nodes 0 & 1.

    Let me know if this doesn’t make sense / if there are further questions. You can test it out by commenting out either/both of the lines & seeing the following assertions fail. @robot-dreams

    The wait_for_helper calls in the connect_nodes implementation wait until the node has received a version and a verack. However, it doesn’t wait until the peer has received a verack. Could this introduce some sort of extremely rare race condition?

    hm, good observation. let’s think this through…

    • as one data point, this function is used a lot (every time we set up a test with more than one node) so I’d imagine we’d see some sporadic failures in misc tests if this was the case. that said, we do have some spurious test failures on CI, so insufficient to rule out entirely.
    • I’m trying to think of what kind of problems this could cause. message processing in bitcoin core is single threaded, so if the peer isn’t processing the VERACK we’ve sent, could it mean a deeper problem where all messages aren’t being processed? or taking forever or something..
    • which leads me to wonder.. what could cause an issue?.. latency should be low, esp since the nodes are local. what are other elements that could cause long time lags?

    I think overall, if a test wanted to do something like “send another message, check that message was received”, it would want to use a wait_until for that assertion to be reliable, which should allow enough flexibility in any delay processing the VERACK. What do you think? @epson121

    Also, similar behaviour can be seen in tests\functional\p2p_disconnect_ban.py L21 and L80, e.g.

    nice catch! I’ve updated the setup on L21. but with L80, we need to leave it in for a similar reason to what I explained earlier for the rpc_net.py test.

  9. amitiuttarwar renamed this:
    [test] Clarify rpc_net functional test
    [test] clarify rpc_net & p2p_disconnect_ban functional tests
    on Sep 11, 2020
  10. michaelfolkson commented at 11:02 am on September 15, 2020: contributor

    Concept ACK.

    Are there any edge cases where the P2P behavior of a one-sided connection is different to a two-sided connection? Do we want to test both or is a two-sided connection sufficient?

  11. amitiuttarwar commented at 8:00 pm on September 16, 2020: contributor
    @michaelfolkson not sure what you mean… I think you’re asking about a subset of the tests?
  12. robot-dreams commented at 9:51 pm on September 16, 2020: contributor

    ACK 00ea3fc8e4d2f545c10970d83ef24648468deb0b

    Thanks for clarifying! I previously had a brain error—for some reason I thought a single connect_nodes call adds connections in both directions. But that’s not the case.

    I tested locally to make sure that the connect_nodes calls you removed were indeed no-ops:

    In addition, the connect_nodes call you kept (on line 147) was actually doing something:

    As for my verack question, thanks for thinking this through! Your suggestions seem very reasonable, and in retrospect I’d be very surprised if the timing actually causes test flakiness. Although I don’t fully understand what’s going on here, I do think further discussion is out of scope for this PR.

  13. DrahtBot commented at 1:56 pm on September 19, 2020: member

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

    Conflicts

    No conflicts as of last run.

  14. DrahtBot added the label Needs rebase on Sep 26, 2020
  15. amitiuttarwar force-pushed on Sep 28, 2020
  16. amitiuttarwar commented at 11:46 pm on September 28, 2020: contributor
    rebased
  17. DrahtBot removed the label Needs rebase on Sep 29, 2020
  18. DrahtBot added the label Needs rebase on Oct 21, 2020
  19. [move-only, test]: Match test order with run order 0672522aed
  20. amitiuttarwar force-pushed on Oct 27, 2020
  21. DrahtBot removed the label Needs rebase on Oct 27, 2020
  22. [test] Clarify setup of node topology.
    Since the test framework automatically sets up a connection between the nodes,
    the second connect_nodes call was a no-op. Remove the redundant call & add
    comments to explain the expected topology.
    47ff5098ad
  23. amitiuttarwar force-pushed on Oct 28, 2020
  24. amitiuttarwar commented at 2:24 am on October 28, 2020: contributor
    rebased
  25. laanwj commented at 8:45 am on October 28, 2020: member
    ACK 47ff5098ad5ea2c20ea387f99940a7cde6c80789
  26. laanwj merged this on Oct 28, 2020
  27. laanwj closed this on Oct 28, 2020

  28. sidhujag referenced this in commit 121e9b9581 on Oct 28, 2020
  29. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me