Strategically sync to prevent intermittent failures
This commit is contained in:
parent
32212cbad7
commit
a482e4c9fa
|
@ -46,6 +46,9 @@ class TxExpiringSoonTest(BitcoinTestFramework):
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def verify_inv(self, testnode, 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
|
# Send p2p message "mempool" to receive contents from zcashd node in "inv" message
|
||||||
with mininode_lock:
|
with mininode_lock:
|
||||||
testnode.last_inv = None
|
testnode.last_inv = None
|
||||||
|
@ -142,7 +145,7 @@ class TxExpiringSoonTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[2].getblockcount(), 201)
|
assert_equal(self.nodes[2].getblockcount(), 201)
|
||||||
|
|
||||||
# Reconnect node 2 to the network
|
# 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
|
# Set up test node for node 2
|
||||||
testnode2 = TestNode()
|
testnode2 = TestNode()
|
||||||
|
@ -175,7 +178,7 @@ class TxExpiringSoonTest(BitcoinTestFramework):
|
||||||
self.send_data_message(testnode0, tx2)
|
self.send_data_message(testnode0, tx2)
|
||||||
|
|
||||||
# Sync up with node after p2p messages delivered
|
# 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
|
# Verify node 0 does not reply to "getdata" by sending "tx" message, as tx2 is expiring soon
|
||||||
with mininode_lock:
|
with mininode_lock:
|
||||||
|
@ -194,6 +197,7 @@ class TxExpiringSoonTest(BitcoinTestFramework):
|
||||||
self.verify_last_tx(testnode0, tx3)
|
self.verify_last_tx(testnode0, tx3)
|
||||||
# Verify txid for tx3 is returned in "inv", but tx2 which is expiring soon is not returned
|
# 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(testnode0, tx3)
|
||||||
|
self.verify_inv(testnode2, tx3)
|
||||||
|
|
||||||
# Verify contents of mempool
|
# Verify contents of mempool
|
||||||
assert_equal({tx2.hash, tx3.hash}, set(self.nodes[0].getrawmempool()))
|
assert_equal({tx2.hash, tx3.hash}, set(self.nodes[0].getrawmempool()))
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
from test_framework.mininode import CTransaction, NodeConnCB, mininode_lock, msg_ping, \
|
from test_framework.mininode import CTransaction, NodeConnCB, mininode_lock, msg_ping, \
|
||||||
msg_pong
|
msg_pong
|
||||||
from test_framework.util import assert_true
|
from test_framework.util import fail
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
import time
|
import time
|
||||||
|
@ -67,16 +67,15 @@ class TestNode(NodeConnCB):
|
||||||
# Sync up with the node after delivery of a message
|
# Sync up with the node after delivery of a message
|
||||||
def sync_with_ping(self, timeout=30):
|
def sync_with_ping(self, timeout=30):
|
||||||
self.connection.send_message(msg_ping(nonce=self.ping_counter))
|
self.connection.send_message(msg_ping(nonce=self.ping_counter))
|
||||||
received_pong = False
|
|
||||||
sleep_time = 0.05
|
sleep_time = 0.05
|
||||||
while not received_pong and timeout > 0:
|
while timeout > 0:
|
||||||
time.sleep(sleep_time)
|
|
||||||
timeout -= sleep_time
|
|
||||||
with mininode_lock:
|
with mininode_lock:
|
||||||
if self.last_pong.nonce == self.ping_counter:
|
if self.last_pong.nonce == self.ping_counter:
|
||||||
received_pong = True
|
self.ping_counter += 1
|
||||||
self.ping_counter += 1
|
return
|
||||||
assert_true(received_pong, "Should have received pong")
|
time.sleep(sleep_time)
|
||||||
|
timeout -= sleep_time
|
||||||
|
fail("Should have received pong")
|
||||||
|
|
||||||
|
|
||||||
def create_transaction(node, coinbase, to_address, amount, expiry_height):
|
def create_transaction(node, coinbase, to_address, amount, expiry_height):
|
||||||
|
|
Loading…
Reference in New Issue