Skip to content

Commit f0c4ab9

Browse files
committed
[tests] fix flakiness in sendheaders.py
Fixes to sources of intermittent failure in sendheaders.py - at the start of test_null_locators(), a new block is generated and then a getheaders is sent. check_last_accouncement() is called to assert that the headers message is received. However, the new block triggers an inv to be sent over both P2P connections, so there's a race. If the inv is received at the wrong time, the test fails. - test_null_locators() ends by sending a block to the node under test. At the start of test_nonnull_locators(), a block is mined and check_last_announcement() is called to assert that the inv received is for the same block. That means there's a race: if the inv from the block sent in test_null_locators() is received at the wrong time, the test fails.
1 parent 25fd6e2 commit f0c4ab9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/functional/sendheaders.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,16 @@ def run_test(self):
243243
inv_node.sync_with_ping()
244244
test_node.sync_with_ping()
245245

246-
self.test_null_locators(test_node)
246+
self.test_null_locators(test_node, inv_node)
247247
self.test_nonnull_locators(test_node, inv_node)
248248

249-
def test_null_locators(self, test_node):
249+
def test_null_locators(self, test_node, inv_node):
250250
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0])
251251
tip_hash = int(tip["hash"], 16)
252252

253+
inv_node.check_last_announcement(inv=[tip_hash], headers=[])
254+
test_node.check_last_announcement(inv=[tip_hash], headers=[])
255+
253256
self.log.info("Verify getheaders with null locator and valid hashstop returns headers.")
254257
test_node.clear_last_announcement()
255258
test_node.send_get_headers(locator=[], hashstop=tip_hash)
@@ -263,7 +266,10 @@ def test_null_locators(self, test_node):
263266
test_node.send_get_headers(locator=[], hashstop=int(block.hash, 16))
264267
test_node.sync_with_ping()
265268
assert_equal(test_node.block_announced, False)
269+
inv_node.clear_last_announcement()
266270
test_node.send_message(msg_block(block))
271+
inv_node.check_last_announcement(inv=[int(block.hash, 16)], headers=[])
272+
inv_node.clear_last_announcement()
267273

268274
def test_nonnull_locators(self, test_node, inv_node):
269275
tip = int(self.nodes[0].getbestblockhash(), 16)

0 commit comments

Comments
 (0)