test: move check_node_connections to util #23392

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2021-10-check-node-connections changing 3 files +9 −14
  1. brunoerg commented at 12:55 AM on October 30, 2021: member

    This function (check_node_connections) exists in feature_anchors.py and p2p_add_connections.py and does the same thing in both, this PR moves this function to util to avoid repetition and facilitate maintenance.

  2. fanquake added the label Tests on Oct 30, 2021
  3. brunoerg force-pushed on Oct 30, 2021
  4. lsilva01 approved
  5. lsilva01 commented at 3:11 AM on October 30, 2021: contributor
  6. brunoerg force-pushed on Nov 17, 2021
  7. stratospher commented at 11:39 AM on November 18, 2021: contributor

    ACK ab9bfc8.

  8. in test/functional/test_framework/util.py:454 in ab9bfc8ad6 outdated
     445 | @@ -445,6 +446,14 @@ def set_node_times(nodes, t):
     446 |          node.setmocktime(t)
     447 |  
     448 |  
     449 | +def check_node_connections(*, node, num_in, num_out):
     450 | +    info = node.getnetworkinfo()
     451 | +    if info["connections_in"] != num_in:
     452 | +        raise AssertionError("connections_in: %s != %s" % (str(info["connections_in"]), str(num_in)))
     453 | +    if info["connections_out"] != num_out:
     454 | +        raise AssertionError("connections_out: %s != %s" % (str(info["connections_out"]), str(num_out)))
    


    MarcoFalke commented at 2:51 PM on November 18, 2021:

    why is this changed?


    brunoerg commented at 2:59 PM on November 18, 2021:

    To get more friendly error messages. It makes easier to indentify if the error happens because in or out connections.


    MarcoFalke commented at 3:05 PM on November 18, 2021:

    assert_equal will already print all needed info, no?


    brunoerg commented at 4:04 PM on November 18, 2021:

    The difference is minimal, example: AssertionError: connections_in: 5 != 3, with assert_equal: AssertionError: not(5 == 4). I can change back to assert_equal if you think its better, np.


    MarcoFalke commented at 4:31 PM on November 18, 2021:

    python will show the stack trace on uncaught exceptions, which shows that the argument was connections_in. So I think there is no difference in practise?


    brunoerg commented at 4:39 PM on November 18, 2021:

    Yes, considering the stack trace, there is no difference. Going to change back to assert_equal.


    brunoerg commented at 4:41 PM on November 18, 2021:

    Done.

  9. MarcoFalke commented at 2:51 PM on November 18, 2021: member

    I think all commits can be squashed into one to allow for easy --color-moved=dimmed-zebra.

  10. brunoerg force-pushed on Nov 18, 2021
  11. brunoerg commented at 2:57 PM on November 18, 2021: member

    I think all commits can be squashed into one to allow for easy --color-moved=dimmed-zebra.

    Done.

  12. test: add check_node_connections in util 988024fe37
  13. brunoerg force-pushed on Nov 18, 2021
  14. laanwj commented at 12:50 PM on November 29, 2021: member

    Code review ACK 988024fe37fe00c2deff28e44593e330aa6191f4

  15. laanwj merged this on Nov 29, 2021
  16. laanwj closed this on Nov 29, 2021

  17. sidhujag referenced this in commit c4a2d39463 on Nov 29, 2021
  18. RandyMcMillan referenced this in commit 382f9f146e on Dec 23, 2021
  19. Fabcien referenced this in commit 00657787e1 on Feb 3, 2022
  20. DrahtBot locked this on Nov 29, 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: 2026-05-02 03:14 UTC

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