From 75b9fc4f2703a76975340f292fa80e76802e4999 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 9 Aug 2021 17:43:48 +0100 Subject: [PATCH] test: Fix race condition in p2p_txexpiringsoon The recent changes to mempool inv logic mean that nodes are much less likely to immediately return an `inv` message in response to a `mempool` message. The `p2p_txexpiringsoon` RPC test was relying on the prior behaviour. `TestNode.sync_with_ping` now takes an optional `waiting_for` closure that allows the caller to require that a specific message kind is received prior to the timeout. --- qa/rpc-tests/p2p_txexpiringsoon.py | 2 +- qa/rpc-tests/tx_expiry_helper.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/p2p_txexpiringsoon.py b/qa/rpc-tests/p2p_txexpiringsoon.py index 6472b6fba..4cc4a38c7 100755 --- a/qa/rpc-tests/p2p_txexpiringsoon.py +++ b/qa/rpc-tests/p2p_txexpiringsoon.py @@ -51,7 +51,7 @@ class TxExpiringSoonTest(BitcoinTestFramework): testnode.send_message(msg_mempool()) # Sync up with node after p2p messages delivered - testnode.sync_with_ping() + testnode.sync_with_ping(waiting_for=lambda x: x.last_inv) with mininode_lock: msg = testnode.last_inv diff --git a/qa/rpc-tests/tx_expiry_helper.py b/qa/rpc-tests/tx_expiry_helper.py index 94a6cc2c5..5b6594add 100755 --- a/qa/rpc-tests/tx_expiry_helper.py +++ b/qa/rpc-tests/tx_expiry_helper.py @@ -66,12 +66,13 @@ class TestNode(NodeConnCB): # The following function is mostly copied from p2p-acceptblock.py # Sync up with the node after delivery of a message - def sync_with_ping(self, timeout=30): + def sync_with_ping(self, timeout=30, waiting_for=None): self.connection.send_message(msg_ping(nonce=self.ping_counter)) sleep_time = 0.05 while timeout > 0: with mininode_lock: - if self.last_pong.nonce == self.ping_counter: + ready = True if waiting_for is None else waiting_for(self) is not None + if ready and self.last_pong.nonce == self.ping_counter: self.ping_counter += 1 return time.sleep(sleep_time)