Skip to content

Commit

Permalink
test: Remove global wait_until from p2p_getdata #
Browse files Browse the repository at this point in the history
Summary:
> Using the global wait_until makes it impossible to adjust the timeout based on the hardware the test is running on.
>
> Fix that by using the mininode member function.

This is a backport of Core [[bitcoin/bitcoin#19060 | PR19060]]

Test Plan: ninja check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9164
  • Loading branch information
MarcoFalke authored and PiRK committed Feb 4, 2021
1 parent 05a6ead commit eebe1aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions test/functional/p2p_getdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
CInv,
msg_getdata,
)
from test_framework.mininode import (
mininode_lock,
P2PInterface,
)
from test_framework.mininode import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import wait_until


class P2PStoreBlock(P2PInterface):

def __init__(self):
super().__init__()
self.blocks = defaultdict(int)
Expand All @@ -33,25 +28,23 @@ def set_test_params(self):
self.num_nodes = 1

def run_test(self):
self.nodes[0].add_p2p_connection(P2PStoreBlock())
p2p_block_store = self.nodes[0].add_p2p_connection(P2PStoreBlock())

self.log.info(
"test that an invalid GETDATA doesn't prevent processing of future messages")

# Send invalid message and verify that node responds to later ping
invalid_getdata = msg_getdata()
invalid_getdata.inv.append(CInv(t=0, h=0)) # INV type 0 is invalid.
self.nodes[0].p2ps[0].send_and_ping(invalid_getdata)
p2p_block_store.send_and_ping(invalid_getdata)

# Check getdata still works by fetching tip block
best_block = int(self.nodes[0].getbestblockhash(), 16)
good_getdata = msg_getdata()
good_getdata.inv.append(CInv(t=2, h=best_block))
self.nodes[0].p2ps[0].send_and_ping(good_getdata)
wait_until(
lambda: self.nodes[0].p2ps[0].blocks[best_block] == 1,
timeout=30,
lock=mininode_lock)
p2p_block_store.send_and_ping(good_getdata)
p2p_block_store.wait_until(
lambda: self.nodes[0].p2ps[0].blocks[best_block] == 1)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def on_version(self, message):

# Connection helper methods

def wait_until(self, test_function, timeout):
def wait_until(self, test_function, timeout=60):
wait_until(test_function, timeout=timeout, lock=mininode_lock,
timeout_factor=self.timeout_factor)

Expand Down

0 comments on commit eebe1aa

Please sign in to comment.