Browse Source

Strategically sync to prevent intermittent failures

pull/245/head
Eirik Ogilvie-Wigley 5 years ago
parent
commit
a482e4c9fa
  1. 8
      qa/rpc-tests/p2p_txexpiringsoon.py
  2. 15
      qa/rpc-tests/tx_expiry_helper.py

8
qa/rpc-tests/p2p_txexpiringsoon.py

@ -46,6 +46,9 @@ class TxExpiringSoonTest(BitcoinTestFramework):
return tx
def verify_inv(self, testnode, tx):
# Make sure we are synced before sending the mempool message
testnode.sync_with_ping()
# Send p2p message "mempool" to receive contents from zcashd node in "inv" message
with mininode_lock:
testnode.last_inv = None
@ -142,7 +145,7 @@ class TxExpiringSoonTest(BitcoinTestFramework):
assert_equal(self.nodes[2].getblockcount(), 201)
# Reconnect node 2 to the network
connect_nodes_bi(self.nodes, 1, 2)
connect_nodes_bi(self.nodes, 0, 2)
# Set up test node for node 2
testnode2 = TestNode()
@ -175,7 +178,7 @@ class TxExpiringSoonTest(BitcoinTestFramework):
self.send_data_message(testnode0, tx2)
# Sync up with node after p2p messages delivered
[x.sync_with_ping() for x in [testnode0, testnode2]]
testnode0.sync_with_ping()
# Verify node 0 does not reply to "getdata" by sending "tx" message, as tx2 is expiring soon
with mininode_lock:
@ -194,6 +197,7 @@ class TxExpiringSoonTest(BitcoinTestFramework):
self.verify_last_tx(testnode0, tx3)
# Verify txid for tx3 is returned in "inv", but tx2 which is expiring soon is not returned
self.verify_inv(testnode0, tx3)
self.verify_inv(testnode2, tx3)
# Verify contents of mempool
assert_equal({tx2.hash, tx3.hash}, set(self.nodes[0].getrawmempool()))

15
qa/rpc-tests/tx_expiry_helper.py

@ -7,7 +7,7 @@
#
from test_framework.mininode import CTransaction, NodeConnCB, mininode_lock, msg_ping, \
msg_pong
from test_framework.util import assert_true
from test_framework.util import fail
import cStringIO
import time
@ -67,16 +67,15 @@ class TestNode(NodeConnCB):
# Sync up with the node after delivery of a message
def sync_with_ping(self, timeout=30):
self.connection.send_message(msg_ping(nonce=self.ping_counter))
received_pong = False
sleep_time = 0.05
while not received_pong and timeout > 0:
time.sleep(sleep_time)
timeout -= sleep_time
while timeout > 0:
with mininode_lock:
if self.last_pong.nonce == self.ping_counter:
received_pong = True
self.ping_counter += 1
assert_true(received_pong, "Should have received pong")
self.ping_counter += 1
return
time.sleep(sleep_time)
timeout -= sleep_time
fail("Should have received pong")
def create_transaction(node, coinbase, to_address, amount, expiry_height):

Loading…
Cancel
Save