aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2024-04-22 17:06:05 +0100
committerglozow <gloriajzhao@gmail.com>2024-04-22 17:06:20 +0100
commitb3106be84f0124f5a84e0a90499ba80e8cd6c60b (patch)
treeb5936f720a24f3f36f6c2ef41289f0d51a4f3ba8 /test
parent04c90f105949f63f19f47950bcfa7bfb249a8125 (diff)
parent6b02c11d667adff24daf611f9b14815d27963674 (diff)
downloadbitcoin-b3106be84f0124f5a84e0a90499ba80e8cd6c60b.tar.xz
Merge bitcoin/bitcoin#29898: test: Fix intermittent issue in p2p_handshake.py
6b02c11d667adff24daf611f9b14815d27963674 test: Fix intermittent issue in p2p_handshake.py (stratospher) Pull request description: When establishing outbound connections [`TestNode` --------> `P2PConnection`], `P2PConnection` listens for a single connection from `TestNode` on a [port which is fixed based on `p2p_idx`](https://github.com/bitcoin/bitcoin/blob/312f54278fd972ba3557c6a5b805fd244a063959/test/functional/test_framework/p2p.py#L746). If we reuse the same port when disconnecting and establishing connections again, we might hit this scenario where: - disconnection is done on python side for `P2PConnection` - disconnection not complete on c++ side for `TestNode` - we're trying to establish a new connection on same port again Prevent this scenario from happening by ensuring disconnection on c++ side for TestNode as well. One way to reproduce this on master would be adding a sleep statement before disconnection happens on c++ side. ```diff diff --git a/src/net.cpp b/src/net.cpp index e388f05b03..62507d1f39 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2112,6 +2112,7 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes, if (!pnode->fDisconnect) { LogPrint(BCLog::NET, "socket closed for peer=%d\n", pnode->GetId()); } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); pnode->CloseSocketDisconnect(); } else if (nBytes < 0) ``` ACKs for top commit: maflcko: lgtm ACK 6b02c11d667adff24daf611f9b14815d27963674 mzumsande: Tested ACK 6b02c11d667adff24daf611f9b14815d27963674 BrandonOdiwuor: Tested ACK 6b02c11d667adff24daf611f9b14815d27963674 theStack: Tested ACK 6b02c11d667adff24daf611f9b14815d27963674 glozow: ACK 6b02c11d667adff24daf611f9b14815d27963674 Tree-SHA512: 69509edb61ba45739fd585b6cc8a254f412975c124a5b5a52688288ecaaffd264dd76019b8290cc34c26c3ac2dfe477965ee5a11d7aabdd8e4d2a75229a4a068
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/p2p_handshake.py1
1 files changed, 1 insertions, 0 deletions
diff --git a/test/functional/p2p_handshake.py b/test/functional/p2p_handshake.py
index f0b62e291d..dd19fe9333 100755
--- a/test/functional/p2p_handshake.py
+++ b/test/functional/p2p_handshake.py
@@ -41,6 +41,7 @@ class P2PHandshakeTest(BitcoinTestFramework):
peer.sync_with_ping()
peer.peer_disconnect()
peer.wait_for_disconnect()
+ self.wait_until(lambda: len(node.getpeerinfo()) == 0)
def test_desirable_service_flags(self, node, service_flag_tests, desirable_service_flags, expect_disconnect):
"""Check that connecting to a peer either fails or succeeds depending on its offered