Skip to content

Commit ddc0a60

Browse files
author
MarcoFalke
committed
Merge #18617: test: add factor option to adjust test timeouts
2742c34 test: add factor option to adjust test timeouts (Harris) Pull request description: This PR adds a new option **factor** that can be used to adjust timeouts in various functional tests. Several timeouts and functions from `authproxy`, `mininode`, `test_node` and `util` have been adapted to use this option. The factor-option definition is located in `test_framework.py`. Fixes bitcoin/bitcoin#18266 Also Fixes bitcoin/bitcoin#18834 ACKs for top commit: MarcoFalke: Thanks! ACK 2742c34 Tree-SHA512: 6d8421933ba2ac1b7db00b70cf2bc242d9842c48121c11aadc30b0985c4a174c86a127d6402d0cd73b993559d60d4f747872d21f9510cf4806e008349780d3ef
2 parents 68ef952 + 2742c34 commit ddc0a60

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

ci/test/00_setup_env_native_valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export NO_DEPENDS=1
1313
if [[ "${TRAVIS}" == "true" && "${TRAVIS_REPO_SLUG}" != "bitcoin/bitcoin" ]]; then
1414
export TEST_RUNNER_EXTRA="wallet_disable" # Only run wallet_disable as a smoke test to not hit the 50 min travis time limit
1515
else
16-
export TEST_RUNNER_EXTRA="--exclude rpc_bind" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
16+
export TEST_RUNNER_EXTRA="--exclude rpc_bind --factor=2" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
1717
fi
1818
export GOAL="install"
1919
export BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=no CC=clang CXX=clang++" # TODO enable GUI

test/functional/test_framework/mininode.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ def __init__(self):
120120
def is_connected(self):
121121
return self._transport is not None
122122

123-
def peer_connect(self, dstaddr, dstport, *, net):
123+
def peer_connect(self, dstaddr, dstport, *, net, factor):
124124
assert not self.is_connected
125+
self.factor = factor
125126
self.dstaddr = dstaddr
126127
self.dstport = dstport
127128
# The initial message to send after the connection was made:
@@ -367,9 +368,12 @@ def on_version(self, message):
367368

368369
# Connection helper methods
369370

371+
def wait_until(self, test_function, timeout):
372+
wait_until(test_function, timeout=timeout, lock=mininode_lock, factor=self.factor)
373+
370374
def wait_for_disconnect(self, timeout=60):
371375
test_function = lambda: not self.is_connected
372-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
376+
self.wait_until(test_function, timeout=timeout)
373377

374378
# Message receiving helper methods
375379

@@ -380,14 +384,14 @@ def test_function():
380384
return False
381385
return self.last_message['tx'].tx.rehash() == txid
382386

383-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
387+
self.wait_until(test_function, timeout=timeout)
384388

385389
def wait_for_block(self, blockhash, timeout=60):
386390
def test_function():
387391
assert self.is_connected
388392
return self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
389393

390-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
394+
self.wait_until(test_function, timeout=timeout)
391395

392396
def wait_for_header(self, blockhash, timeout=60):
393397
def test_function():
@@ -397,7 +401,7 @@ def test_function():
397401
return False
398402
return last_headers.headers[0].rehash() == int(blockhash, 16)
399403

400-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
404+
self.wait_until(test_function, timeout=timeout)
401405

402406
def wait_for_merkleblock(self, blockhash, timeout=60):
403407
def test_function():
@@ -407,7 +411,7 @@ def test_function():
407411
return False
408412
return last_filtered_block.merkleblock.header.rehash() == int(blockhash, 16)
409413

410-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
414+
self.wait_until(test_function, timeout=timeout)
411415

412416
def wait_for_getdata(self, hash_list, timeout=60):
413417
"""Waits for a getdata message.
@@ -421,7 +425,7 @@ def test_function():
421425
return False
422426
return [x.hash for x in last_data.inv] == hash_list
423427

424-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
428+
self.wait_until(test_function, timeout=timeout)
425429

426430
def wait_for_getheaders(self, timeout=60):
427431
"""Waits for a getheaders message.
@@ -435,7 +439,7 @@ def test_function():
435439
assert self.is_connected
436440
return self.last_message.get("getheaders")
437441

438-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
442+
self.wait_until(test_function, timeout=timeout)
439443

440444
def wait_for_inv(self, expected_inv, timeout=60):
441445
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
@@ -448,13 +452,13 @@ def test_function():
448452
self.last_message["inv"].inv[0].type == expected_inv[0].type and \
449453
self.last_message["inv"].inv[0].hash == expected_inv[0].hash
450454

451-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
455+
self.wait_until(test_function, timeout=timeout)
452456

453457
def wait_for_verack(self, timeout=60):
454458
def test_function():
455459
return self.message_count["verack"]
456460

457-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
461+
self.wait_until(test_function, timeout=timeout)
458462

459463
# Message sending helper functions
460464

@@ -470,7 +474,7 @@ def test_function():
470474
assert self.is_connected
471475
return self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter
472476

473-
wait_until(test_function, timeout=timeout, lock=mininode_lock)
477+
self.wait_until(test_function, timeout=timeout)
474478
self.ping_counter += 1
475479

476480

@@ -586,15 +590,15 @@ def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False,
586590
self.send_message(msg_block(block=b))
587591
else:
588592
self.send_message(msg_headers([CBlockHeader(block) for block in blocks]))
589-
wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)
593+
self.wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout)
590594

591595
if expect_disconnect:
592596
self.wait_for_disconnect(timeout=timeout)
593597
else:
594598
self.sync_with_ping(timeout=timeout)
595599

596600
if success:
597-
wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
601+
self.wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
598602
else:
599603
assert node.getbestblockhash() != blocks[-1].hash
600604

test/functional/test_framework/test_framework.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self):
102102
self.bind_to_localhost_only = True
103103
self.set_test_params()
104104
self.parse_args()
105+
self.rpc_timeout = int(self.rpc_timeout * self.options.factor) # optionally, increase timeout by a factor
105106

106107
def main(self):
107108
"""Main function. This should not be overridden by the subclass test scripts."""
@@ -168,6 +169,7 @@ def parse_args(self):
168169
help="set a random seed for deterministically reproducing a previous test run")
169170
parser.add_argument("--descriptors", default=False, action="store_true",
170171
help="Run test using a descriptor wallet")
172+
parser.add_argument('--factor', type=float, default=1.0, help='adjust test timeouts by a factor')
171173
self.add_options(parser)
172174
self.options = parser.parse_args()
173175

@@ -433,6 +435,7 @@ def get_bin_from_version(version, bin_name, bin_default):
433435
chain=self.chain,
434436
rpchost=rpchost,
435437
timewait=self.rpc_timeout,
438+
factor=self.options.factor,
436439
bitcoind=binary[i],
437440
bitcoin_cli=binary_cli[i],
438441
version=versions[i],
@@ -579,6 +582,7 @@ def _initialize_chain(self):
579582
extra_args=['-disablewallet'],
580583
rpchost=None,
581584
timewait=self.rpc_timeout,
585+
factor=self.options.factor,
582586
bitcoind=self.options.bitcoind,
583587
bitcoin_cli=self.options.bitcoincli,
584588
coverage_dir=None,

test/functional/test_framework/test_node.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TestNode():
6262
To make things easier for the test writer, any unrecognised messages will
6363
be dispatched to the RPC connection."""
6464

65-
def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
65+
def __init__(self, i, datadir, *, chain, rpchost, timewait, factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
6666
"""
6767
Kwargs:
6868
start_perf (bool): If True, begin profiling the node with `perf` as soon as
@@ -128,6 +128,7 @@ def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cl
128128
self.perf_subprocesses = {}
129129

130130
self.p2ps = []
131+
self.factor = factor
131132

132133
AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
133134
PRIV_KEYS = [
@@ -324,13 +325,13 @@ def is_node_stopped(self):
324325
return True
325326

326327
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
327-
wait_until(self.is_node_stopped, timeout=timeout)
328+
wait_until(self.is_node_stopped, timeout=timeout, factor=self.factor)
328329

329330
@contextlib.contextmanager
330331
def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
331332
if unexpected_msgs is None:
332333
unexpected_msgs = []
333-
time_end = time.time() + timeout
334+
time_end = time.time() + timeout * self.factor
334335
debug_log = os.path.join(self.datadir, self.chain, 'debug.log')
335336
with open(debug_log, encoding='utf-8') as dl:
336337
dl.seek(0, 2)
@@ -487,7 +488,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
487488
if 'dstaddr' not in kwargs:
488489
kwargs['dstaddr'] = '127.0.0.1'
489490

490-
p2p_conn.peer_connect(**kwargs, net=self.chain)()
491+
p2p_conn.peer_connect(**kwargs, net=self.chain, factor=self.factor)()
491492
self.p2ps.append(p2p_conn)
492493
if wait_for_verack:
493494
# Wait for the node to send us the version and verack

test/functional/test_framework/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ def str_to_b64str(string):
208208
def satoshi_round(amount):
209209
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
210210

211-
def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None):
211+
def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, factor=1.0):
212212
if attempts == float('inf') and timeout == float('inf'):
213213
timeout = 60
214+
timeout = timeout * factor
214215
attempt = 0
215216
time_end = time.time() + timeout
216217

@@ -265,7 +266,7 @@ def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
265266
"""
266267
proxy_kwargs = {}
267268
if timeout is not None:
268-
proxy_kwargs['timeout'] = timeout
269+
proxy_kwargs['timeout'] = int(timeout)
269270

270271
proxy = AuthServiceProxy(url, **proxy_kwargs)
271272
proxy.url = url # store URL on proxy for info

0 commit comments

Comments
 (0)