test: disconnect_nodes should warn if nodes were already disconnected #18890

pull robot-visions wants to merge 3 commits into bitcoin:master from robot-visions:disconnect-nodes changing 6 files +17 −11
  1. robot-visions commented at 5:59 PM on May 5, 2020: contributor

    There's no harm in calling disconnect_nodes for nodes that weren't connected (in this case it's a no-op). However, detecting this case and logging a warning can help ensure that tests are behaving as expected.

    In addition, since disconnect_nodes works bidirectionally, I removed all instances of this pattern:

    disconnect_nodes(self.nodes[0], 1)
    disconnect_nodes(self.nodes[1], 0)
    
  2. DrahtBot added the label Tests on May 5, 2020
  3. test: warn if nodes not connected before disconnect_nodes a9bd1f9adf
  4. test: remove redundant two-way disconnect_nodes calls e6e7abd51a
  5. test: Remove unnecessary disconnect_nodes call in rpc_psbt.py 34e641a564
  6. robot-visions force-pushed on May 7, 2020
  7. in test/functional/test_framework/util.py:389 in a9bd1f9adf outdated
     385 | +    def get_peer_ids():
     386 | +        result = []
     387 | +        for peer in from_connection.getpeerinfo():
     388 | +            if "testnode{}".format(node_num) in peer['subver']:
     389 | +                result.append(peer['id'])
     390 | +        return result
    


    amitiuttarwar commented at 7:55 PM on May 26, 2020:

    is my understanding correct that there should only be one matching result, but technically multiple are possible?


    MarcoFalke commented at 2:37 PM on May 27, 2020:

    The tests used to spin up two connections between all nodes. (One incoming and one outgoing) I hope they don't do that anymore, but it seems ok to still support the use case here and not change behaviour.

  8. amitiuttarwar commented at 9:35 PM on May 26, 2020: contributor

    ACK 34e641a564. Thanks for this test improvement!

    I read through the code, double checked that the warning would actually get thrown & carefully thought through potential sync issues with removing the two way disconnections from the tests.

    some context for reviewers: this PR would have helped prevent a bug in the tests I introduced here

    • nice cleanup to disconnect_nodes! I didn't know about nested functions. Your cleanup makes the function much more understandable.

    • RE: removing redundant disconnect_nodes call / possible sync issues. I was trying to understand if there could be some difference in timing if we call disconnect_nodes on both sides of the connection from the tests VS letting one side instigate. My conclusion is that there is room for some delay, but I'd anticipate a short one (esp when running tests and the latency between nodes is negligible).

    • I also don't think it could cause issues in the tests where it's been removed. This is further supported by the general test pattern of calling disconnect nodes once. If we found possible issues, we'd want to encapsulate a behavior update in the disconnect_nodes function.

    to share my current understanding / how I arrived to the trivial time delay conclusion -

    • the util.py#disconnect_nodes helper function calls the disconnectnodes RPC endpoint, which passes the info through to one of the CConnman::DisconnectNode functions (depending on arg type). This marks the peer for disconnect & then returns.

    • ThreadSocketHandler picks up the peers marked for fDisconnect and initiates the actual "close connection" process, involving the TCP messages sent back and forth to get the connection into the final CLOSED state.

    • both steps have room for delays, but I'd expect the delay to be trivial for both steps in the tests. the socket handler thread should service the peers for disconnect quickly, and the closing process should also be very quick with both nodes running on the same computer.

    lots of words to say, I like this test improvement !

  9. DrahtBot commented at 2:59 AM on June 8, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19198 (test: Check that peers with forcerelay permission are not asked to feefilter by MarcoFalke)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  10. MarcoFalke commented at 12:56 PM on June 8, 2020: member

    review ACK 34e641a564531853342b03db2d9f0bf52b6e439e 👔

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    review ACK 34e641a564531853342b03db2d9f0bf52b6e439e 👔
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUjASgwApe/X03pNFGi8C2KFe9WixRikfexgxgLJjDiexlYqvEvc4OjDiqekq2SF
    pOHmVufldCWYpF7bWjdsYo37XWTkisWV4wwVe1zW4bA4nUXs5DlYSQM5OlPWpeYy
    KBzd21axY5IffYhLnr9zjN24rUu0lutcKsq2U0gdlB8Qq5ZCodPRh0NJr/sBTiyP
    xa2PPJqpo1q562Ew3Mtbj7HyuYmHhKs6+Kil0mlTz4pDjX2kkSdyZ4TpKriHlxNk
    VOwdocOECk6pFcr/6bh1UcX5mj+iqqSf78bREx9CIoWzbNqZ4O8x9igJzv6bfKrc
    Nvyg+AfGGDwDgpn7EzOYZi6CBMeX51xTZubB1fzcFlv8/7QKLANHTz9XuW4pDdgJ
    CQCTOwojxMxWZy5EdsOSd+e/B6/rsMtS3CScYgieVAaGNEgmfaWp8y5YVlIR4HBr
    Y3ovuYXQI7fgMSC7s2MSnLHdzqHuVJfMEPTN+w8dr2Yu5JwO1h1WSjjoGuX6etg7
    9T2l3ZJN
    =Ln1l
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash ff596bcd039e1137cd917886d4c1c72c69e5e6e01d537a557aa029722aa928df -

    </details>

  11. MarcoFalke merged this on Jun 8, 2020
  12. MarcoFalke closed this on Jun 8, 2020

  13. jonatack commented at 1:15 PM on June 8, 2020: member

    ACK 34e641a564531853342b03db2d9f0bf52b6e439e

    Nice idea. Code review and verified the warnings on master.

  14. sidhujag referenced this in commit e48587fa64 on Jun 8, 2020
  15. Fabcien referenced this in commit 49ccd05ff3 on May 14, 2021
  16. 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: 2026-05-02 03:14 UTC

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