Merge #19060: test: Remove global wait_until from p2p_getdata

fa80b4788bbe3ef00c5d767c0d89ba9809d8707c test: Remove global wait_until from p2p_getdata (MarcoFalke)
999922baed3a80b581ce46daa01c4cbca4fcbfd8 test: Default mininode.wait_until timeout to 60s (MarcoFalke)
fab47375fe0bdec1e557e087fdb0707c4dfa7cc2 test: pep-8 p2p_getdata.py (MarcoFalke)

Pull request description:

  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.

  So for example, `./test/functional/p2p_getdata.py  --timeout-factor=0.04` gives a timeout of 2.4 seconds.

ACKs for top commit:
  laanwj:
    ACK fa80b4788bbe3ef00c5d767c0d89ba9809d8707c

Tree-SHA512: ebb1b7860a64451de2b8ee9a0966faddb13b84af711f6744e8260d7c9bc0b382e8fb259897df5212190821e850ed30d4d5c2d7af45a97f207fd4511b06b6674a
This commit is contained in:
Wladimir J. van der Laan 2020-05-26 18:27:21 +02:00 committed by PastaPastaPasta
parent de50c799d4
commit 08a7d1118f
2 changed files with 9 additions and 11 deletions

View File

@ -9,15 +9,11 @@ from test_framework.messages import (
CInv, CInv,
msg_getdata, msg_getdata,
) )
from test_framework.mininode import ( from test_framework.mininode import P2PInterface
mininode_lock,
P2PInterface,
)
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import wait_until
class P2PStoreBlock(P2PInterface): class P2PStoreBlock(P2PInterface):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.blocks = defaultdict(int) self.blocks = defaultdict(int)
@ -26,26 +22,28 @@ class P2PStoreBlock(P2PInterface):
message.block.calc_sha256() message.block.calc_sha256()
self.blocks[message.block.sha256] += 1 self.blocks[message.block.sha256] += 1
class GetdataTest(BitcoinTestFramework): class GetdataTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 1 self.num_nodes = 1
def run_test(self): 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") 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 # Send invalid message and verify that node responds to later ping
invalid_getdata = msg_getdata() invalid_getdata = msg_getdata()
invalid_getdata.inv.append(CInv(t=0, h=0)) # INV type 0 is invalid. 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 # Check getdata still works by fetching tip block
best_block = int(self.nodes[0].getbestblockhash(), 16) best_block = int(self.nodes[0].getbestblockhash(), 16)
good_getdata = msg_getdata() good_getdata = msg_getdata()
good_getdata.inv.append(CInv(t=2, h=best_block)) good_getdata.inv.append(CInv(t=2, h=best_block))
self.nodes[0].p2ps[0].send_and_ping(good_getdata) p2p_block_store.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.wait_until(lambda: self.nodes[0].p2ps[0].blocks[best_block] == 1)
if __name__ == '__main__': if __name__ == '__main__':
GetdataTest().main() GetdataTest().main()

View File

@ -436,7 +436,7 @@ class P2PInterface(P2PConnection):
# Connection helper methods # 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) wait_until(test_function, timeout=timeout, lock=mininode_lock, timeout_factor=self.timeout_factor)
def wait_for_disconnect(self, timeout=60): def wait_for_disconnect(self, timeout=60):