diff options
author | John Newbery <john@johnnewbery.com> | 2017-12-11 12:08:33 -0500 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2017-12-19 11:20:12 -0500 |
commit | 2e029845919eedcb4c4ff5f951cc85d95da68ad1 (patch) | |
tree | feac4789f1ca03f23b8a5f7e31c4bd0b81e99994 /test/functional | |
parent | dbfe294805a094ba4ed6178a56d0a7588fcd8c27 (diff) |
[tests] node_network_limited - remove race condition
node_network_limited had a race condition, since wait_for_block()
doesn't do what you might expect. It only checks the most recent block
received over the P2P interface (perhaps we should rename the method
wait_for_most_recent_block() to avoid future confusion). The test can
fail if the node sends us invs for other blocks, we respond with a
getdata, and the node sends us one of those blocks in the 0.05 second
wait_until loop window.
Fix this by not responding to inv messages with getdata messages.
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/node_network_limited.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/test/functional/node_network_limited.py b/test/functional/node_network_limited.py index 1e7c61b44c..6f1c60eec9 100755 --- a/test/functional/node_network_limited.py +++ b/test/functional/node_network_limited.py @@ -2,15 +2,15 @@ # Copyright (c) 2017 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -from test_framework.messages import CInv, msg_getdata, msg_verack +from test_framework.messages import CInv, msg_getdata from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal -class BaseNode(P2PInterface): - nServices = 0 - def on_version(self, message): - self.nServices = message.nServices +class P2PIgnoreInv(P2PInterface): + def on_inv(self, message): + # The node will send us invs for other blocks. Ignore them. + pass class NodeNetworkLimitedTest(BitcoinTestFramework): def set_test_params(self): @@ -19,7 +19,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework): self.extra_args = [['-prune=550']] def get_signalled_service_flags(self): - node = self.nodes[0].add_p2p_connection(BaseNode()) + node = self.nodes[0].add_p2p_connection(P2PIgnoreInv()) NetworkThread().start() node.wait_for_verack() services = node.nServices @@ -28,10 +28,9 @@ class NodeNetworkLimitedTest(BitcoinTestFramework): return services def try_get_block_via_getdata(self, blockhash, must_disconnect): - node = self.nodes[0].add_p2p_connection(BaseNode()) + node = self.nodes[0].add_p2p_connection(P2PIgnoreInv()) NetworkThread().start() node.wait_for_verack() - node.send_message(msg_verack()) getdata_request = msg_getdata() getdata_request.inv.append(CInv(2, int(blockhash, 16))) node.send_message(getdata_request) |