Skip to content

Commit c4214d0

Browse files
author
MarcoFalke
committed
Merge #21117: test: remove assert_blockchain_height
fa0a4d6 test: remove assert_blockchain_height (MarcoFalke) Pull request description: This simplifies the code and solves intermittent timeouts caused by commit 0d39b58. E.g. https://cirrus-ci.com/task/5196092369272832?command=ci#L3126 ``` test 2021-02-08T12:27:56.275000Z TestFramework (ERROR): Assertion failed Traceback (most recent call last): File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 127, in main self.run_test() File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/feature_assumevalid.py", line 180, in run_test self.assert_blockchain_height(self.nodes[0], 101) File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/feature_assumevalid.py", line 92, in assert_blockchain_height assert False, "blockchain too short after timeout: %d" % current_height AssertionError: blockchain too short after timeout: 101 ACKs for top commit: glozow: ACK fa0a4d6 Tree-SHA512: 3859b0c1581c21f03c775f119204cc3a219e5d86346883634886f6da46feaf254b9c6c49c1ec4581ffe409cdf05f6e91ec38c3976c3daf4a9e67f96ddc1e0dce
2 parents a0077a8 + fa0a4d6 commit c4214d0

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

test/functional/feature_assumevalid.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
block 200. node2 will reject block 102 since it's assumed valid, but it
3030
isn't buried by at least two weeks' work.
3131
"""
32-
import time
3332

34-
from test_framework.blocktools import (create_block, create_coinbase)
33+
from test_framework.blocktools import (
34+
create_block,
35+
create_coinbase,
36+
)
3537
from test_framework.key import ECKey
3638
from test_framework.messages import (
3739
CBlockHeader,
@@ -79,24 +81,6 @@ def send_blocks_until_disconnected(self, p2p_conn):
7981
assert not p2p_conn.is_connected
8082
break
8183

82-
def assert_blockchain_height(self, node, height):
83-
"""Wait until the blockchain is no longer advancing and verify it's reached the expected height."""
84-
last_height = node.getblock(node.getbestblockhash())['height']
85-
timeout = 10
86-
while True:
87-
time.sleep(0.25)
88-
current_height = node.getblock(node.getbestblockhash())['height']
89-
if current_height != last_height:
90-
last_height = current_height
91-
if timeout < 0:
92-
assert False, "blockchain too short after timeout: %d" % current_height
93-
timeout -= 0.25
94-
continue
95-
elif current_height > height:
96-
assert False, "blockchain too long: %d" % current_height
97-
elif current_height == height:
98-
break
99-
10084
def run_test(self):
10185
p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
10286

@@ -177,7 +161,8 @@ def run_test(self):
177161

178162
# Send blocks to node0. Block 102 will be rejected.
179163
self.send_blocks_until_disconnected(p2p0)
180-
self.assert_blockchain_height(self.nodes[0], 101)
164+
self.wait_until(lambda: self.nodes[0].getblockcount() >= 101)
165+
assert_equal(self.nodes[0].getblockcount(), 101)
181166

182167
# Send all blocks to node1. All blocks will be accepted.
183168
for i in range(2202):
@@ -188,7 +173,8 @@ def run_test(self):
188173

189174
# Send blocks to node2. Block 102 will be rejected.
190175
self.send_blocks_until_disconnected(p2p2)
191-
self.assert_blockchain_height(self.nodes[2], 101)
176+
self.wait_until(lambda: self.nodes[2].getblockcount() >= 101)
177+
assert_equal(self.nodes[2].getblockcount(), 101)
192178

193179

194180
if __name__ == '__main__':

0 commit comments

Comments
 (0)