Skip to content

Commit 1343c86

Browse files
committed
test: Update wait_until usage in tests not to use the one from utils
Replace "wait_until()" usage from utils, with the ones from BitcoinTestFramework and P2PInterface. closes bitcoin#19080
1 parent 93ab136 commit 1343c86

26 files changed

+74
-92
lines changed

test/functional/example_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from test_framework.util import (
2727
assert_equal,
2828
connect_nodes,
29-
wait_until,
3029
)
3130

3231
# P2PInterface is a class containing callbacks to be executed when a P2P
@@ -203,7 +202,7 @@ def run_test(self):
203202

204203
# wait_until() will loop until a predicate condition is met. Use it to test properties of the
205204
# P2PInterface objects.
206-
wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=p2p_lock)
205+
self.nodes[2].p2p.wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5)
207206

208207
self.log.info("Check that each block was received only once")
209208
# The network thread uses a global lock on data access to the P2PConnection objects when sending and receiving

test/functional/feature_abortnode.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
from test_framework.test_framework import BitcoinTestFramework
14-
from test_framework.util import wait_until, get_datadir_path, connect_nodes
14+
from test_framework.util import get_datadir_path, connect_nodes
1515
import os
1616

1717

@@ -41,7 +41,7 @@ def run_test(self):
4141

4242
# Check that node0 aborted
4343
self.log.info("Waiting for crash")
44-
wait_until(lambda: self.nodes[0].is_node_stopped(), timeout=200)
44+
self.nodes[0].wait_until_stopped(timeout=200)
4545
self.log.info("Node crashed - now verifying restart fails")
4646
self.nodes[0].assert_start_raises_init_error()
4747

test/functional/feature_notifications.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import (
1111
assert_equal,
12-
wait_until,
1312
connect_nodes,
1413
disconnect_nodes,
1514
hex_str_to_bytes,
@@ -56,15 +55,15 @@ def run_test(self):
5655
blocks = self.nodes[1].generatetoaddress(block_count, self.nodes[1].getnewaddress() if self.is_wallet_compiled() else ADDRESS_BCRT1_UNSPENDABLE)
5756

5857
# wait at most 10 seconds for expected number of files before reading the content
59-
wait_until(lambda: len(os.listdir(self.blocknotify_dir)) == block_count, timeout=10)
58+
self.wait_until(lambda: len(os.listdir(self.blocknotify_dir)) == block_count, timeout=10)
6059

6160
# directory content should equal the generated blocks hashes
6261
assert_equal(sorted(blocks), sorted(os.listdir(self.blocknotify_dir)))
6362

6463
if self.is_wallet_compiled():
6564
self.log.info("test -walletnotify")
6665
# wait at most 10 seconds for expected number of files before reading the content
67-
wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
66+
self.wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
6867

6968
# directory content should equal the generated transaction hashes
7069
txids_rpc = list(map(lambda t: notify_outputname(self.wallet, t['txid']), self.nodes[1].listtransactions("*", block_count)))
@@ -78,7 +77,7 @@ def run_test(self):
7877
self.start_node(1)
7978
connect_nodes(self.nodes[0], 1)
8079

81-
wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
80+
self.wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
8281

8382
# directory content should equal the generated transaction hashes
8483
txids_rpc = list(map(lambda t: notify_outputname(self.wallet, t['txid']), self.nodes[1].listtransactions("*", block_count)))
@@ -140,7 +139,7 @@ def run_test(self):
140139
# TODO: add test for `-alertnotify` large fork notifications
141140

142141
def expect_wallet_notify(self, tx_ids):
143-
wait_until(lambda: len(os.listdir(self.walletnotify_dir)) >= len(tx_ids), timeout=10)
142+
self.wait_until(lambda: len(os.listdir(self.walletnotify_dir)) >= len(tx_ids), timeout=10)
144143
assert_equal(sorted(notify_outputname(self.wallet, tx_id) for tx_id in tx_ids), sorted(os.listdir(self.walletnotify_dir)))
145144
for tx_file in os.listdir(self.walletnotify_dir):
146145
os.remove(os.path.join(self.walletnotify_dir, tx_file))

test/functional/feature_pruning.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
assert_raises_rpc_error,
2121
connect_nodes,
2222
disconnect_nodes,
23-
wait_until,
2423
)
2524

2625
# Rescans start at the earliest block up to 2 hours before a key timestamp, so
@@ -136,7 +135,7 @@ def test_height_min(self):
136135
mine_large_blocks(self.nodes[0], 25)
137136

138137
# Wait for blk00000.dat to be pruned
139-
wait_until(lambda: not os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), timeout=30)
138+
self.wait_until(lambda: not os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), timeout=30)
140139

141140
self.log.info("Success")
142141
usage = calc_usage(self.prunedir)
@@ -250,7 +249,7 @@ def reorg_back(self):
250249

251250
self.log.info("Verify node 2 reorged back to the main chain, some blocks of which it had to redownload")
252251
# Wait for Node 2 to reorg to proper height
253-
wait_until(lambda: self.nodes[2].getblockcount() >= goalbestheight, timeout=900)
252+
self.wait_until(lambda: self.nodes[2].getblockcount() >= goalbestheight, timeout=900)
254253
assert_equal(self.nodes[2].getbestblockhash(), goalbesthash)
255254
# Verify we can now have the data for a block previously pruned
256255
assert_equal(self.nodes[2].getblock(self.forkhash)["height"], self.forkheight)

test/functional/feature_shutdown.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""Test bitcoind shutdown."""
66

77
from test_framework.test_framework import BitcoinTestFramework
8-
from test_framework.util import assert_equal, get_rpc_proxy, wait_until
8+
from test_framework.util import assert_equal, get_rpc_proxy
99
from threading import Thread
1010

1111
def test_long_call(node):
@@ -25,7 +25,7 @@ def run_test(self):
2525
node.getblockcount()
2626
Thread(target=test_long_call, args=(node,)).start()
2727
# Wait until the server is executing the above `waitfornewblock`.
28-
wait_until(lambda: len(self.nodes[0].getrpcinfo()['active_commands']) == 2)
28+
self.wait_until(lambda: len(self.nodes[0].getrpcinfo()['active_commands']) == 2)
2929
# Wait 1 second after requesting shutdown but not before the `stop` call
3030
# finishes. This is to ensure event loop waits for current connections
3131
# to close.

test/functional/feature_versionbits_warning.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from test_framework.messages import msg_block
1515
from test_framework.p2p import p2p_lock, P2PInterface
1616
from test_framework.test_framework import BitcoinTestFramework
17-
from test_framework.util import wait_until
1817

1918
VB_PERIOD = 144 # versionbits period length for regtest
2019
VB_THRESHOLD = 108 # versionbits activation threshold for regtest
@@ -91,14 +90,14 @@ def run_test(self):
9190

9291
# Generating one block guarantees that we'll get out of IBD
9392
node.generatetoaddress(1, node_deterministic_address)
94-
wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=p2p_lock)
93+
self.wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=p2p_lock)
9594
# Generating one more block will be enough to generate an error.
9695
node.generatetoaddress(1, node_deterministic_address)
9796
# Check that get*info() shows the versionbits unknown rules warning
9897
assert WARN_UNKNOWN_RULES_ACTIVE in node.getmininginfo()["warnings"]
9998
assert WARN_UNKNOWN_RULES_ACTIVE in node.getnetworkinfo()["warnings"]
10099
# Check that the alert file shows the versionbits unknown rules warning
101-
wait_until(lambda: self.versionbits_in_alert_file(), timeout=60)
100+
self.wait_until(lambda: self.versionbits_in_alert_file())
102101

103102
if __name__ == '__main__':
104103
VersionBitsWarningTest().main()

test/functional/mempool_packages.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
assert_equal,
1414
assert_raises_rpc_error,
1515
satoshi_round,
16-
wait_until,
1716
)
1817

1918
# default limits
@@ -269,8 +268,8 @@ def run_test(self):
269268
# - txs from previous ancestor test (-> custom ancestor limit)
270269
# - parent tx for descendant test
271270
# - txs chained off parent tx (-> custom descendant limit)
272-
wait_until(lambda: len(self.nodes[1].getrawmempool(False)) ==
273-
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
271+
self.wait_until(lambda: len(self.nodes[1].getrawmempool(False)) ==
272+
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
274273
mempool0 = self.nodes[0].getrawmempool(False)
275274
mempool1 = self.nodes[1].getrawmempool(False)
276275
assert set(mempool1).issubset(set(mempool0))

test/functional/mempool_persist.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
assert_raises_rpc_error,
4848
connect_nodes,
4949
disconnect_nodes,
50-
wait_until,
5150
)
5251

5352

@@ -172,7 +171,7 @@ def test_persist_unbroadcast(self):
172171
# check that txn gets broadcast due to unbroadcast logic
173172
conn = node0.add_p2p_connection(P2PTxInvStore())
174173
node0.mockscheduler(16*60) # 15 min + 1 for buffer
175-
wait_until(lambda: len(conn.get_invs()) == 1)
174+
self.wait_until(lambda: len(conn.get_invs()) == 1)
176175

177176
if __name__ == '__main__':
178177
MempoolPersistTest().main()

test/functional/p2p_blockfilters.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
assert_equal,
2525
connect_nodes,
2626
disconnect_nodes,
27-
wait_until,
2827
)
2928

3029
class CFiltersClient(P2PInterface):
@@ -65,11 +64,11 @@ def run_test(self):
6564
disconnect_nodes(self.nodes[0], 1)
6665

6766
self.nodes[0].generate(1)
68-
wait_until(lambda: self.nodes[0].getblockcount() == 1000)
67+
self.wait_until(lambda: self.nodes[0].getblockcount() == 1000)
6968
stale_block_hash = self.nodes[0].getblockhash(1000)
7069

7170
self.nodes[1].generate(1001)
72-
wait_until(lambda: self.nodes[1].getblockcount() == 2000)
71+
self.wait_until(lambda: self.nodes[1].getblockcount() == 2000)
7372

7473
# Check that nodes have signalled NODE_COMPACT_FILTERS correctly.
7574
assert node0.nServices & NODE_COMPACT_FILTERS != 0

test/functional/p2p_compactblocks.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from test_framework.p2p import p2p_lock, P2PInterface
1515
from test_framework.script import CScript, OP_TRUE, OP_DROP
1616
from test_framework.test_framework import BitcoinTestFramework
17-
from test_framework.util import assert_equal, wait_until, softfork_active
17+
from test_framework.util import assert_equal, softfork_active
1818

1919
# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
2020
class TestP2PConn(P2PInterface):
@@ -73,23 +73,23 @@ def send_header_for_blocks(self, new_blocks):
7373
def request_headers_and_sync(self, locator, hashstop=0):
7474
self.clear_block_announcement()
7575
self.get_headers(locator, hashstop)
76-
wait_until(self.received_block_announcement, timeout=30, lock=p2p_lock)
76+
self.wait_until(self.received_block_announcement, timeout=30)
7777
self.clear_block_announcement()
7878

7979
# Block until a block announcement for a particular block hash is
8080
# received.
8181
def wait_for_block_announcement(self, block_hash, timeout=30):
8282
def received_hash():
8383
return (block_hash in self.announced_blockhashes)
84-
wait_until(received_hash, timeout=timeout, lock=p2p_lock)
84+
self.wait_until(received_hash, timeout=timeout)
8585

8686
def send_await_disconnect(self, message, timeout=30):
8787
"""Sends a message to the node and wait for disconnect.
8888
8989
This is used when we want to send a message into the node that we expect
9090
will get us disconnected, eg an invalid block."""
9191
self.send_message(message)
92-
wait_until(lambda: not self.is_connected, timeout=timeout, lock=p2p_lock)
92+
self.wait_for_disconnect(timeout)
9393

9494
class CompactBlocksTest(BitcoinTestFramework):
9595
def set_test_params(self):
@@ -154,7 +154,7 @@ def test_sendcmpct(self, test_node, old_node=None):
154154
# Make sure we get a SENDCMPCT message from our peer
155155
def received_sendcmpct():
156156
return (len(test_node.last_sendcmpct) > 0)
157-
wait_until(received_sendcmpct, timeout=30, lock=p2p_lock)
157+
test_node.wait_until(received_sendcmpct, timeout=30)
158158
with p2p_lock:
159159
# Check that the first version received is the preferred one
160160
assert_equal(test_node.last_sendcmpct[0].version, preferred_version)
@@ -294,7 +294,7 @@ def test_compactblock_construction(self, test_node, use_witness_address=True):
294294
block.rehash()
295295

296296
# Wait until the block was announced (via compact blocks)
297-
wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30, lock=p2p_lock)
297+
test_node.wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30)
298298

299299
# Now fetch and check the compact block
300300
header_and_shortids = None
@@ -308,7 +308,7 @@ def test_compactblock_construction(self, test_node, use_witness_address=True):
308308
inv = CInv(MSG_CMPCT_BLOCK, block_hash)
309309
test_node.send_message(msg_getdata([inv]))
310310

311-
wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30, lock=p2p_lock)
311+
test_node.wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30)
312312

313313
# Now fetch and check the compact block
314314
header_and_shortids = None
@@ -378,7 +378,7 @@ def test_compactblock_requests(self, test_node, segwit=True):
378378

379379
if announce == "inv":
380380
test_node.send_message(msg_inv([CInv(MSG_BLOCK, block.sha256)]))
381-
wait_until(lambda: "getheaders" in test_node.last_message, timeout=30, lock=p2p_lock)
381+
test_node.wait_until(lambda: "getheaders" in test_node.last_message, timeout=30)
382382
test_node.send_header_for_blocks([block])
383383
else:
384384
test_node.send_header_for_blocks([block])
@@ -588,7 +588,7 @@ def test_getblocktxn_handler(self, test_node):
588588
num_to_request = random.randint(1, len(block.vtx))
589589
msg.block_txn_request.from_absolute(sorted(random.sample(range(len(block.vtx)), num_to_request)))
590590
test_node.send_message(msg)
591-
wait_until(lambda: "blocktxn" in test_node.last_message, timeout=10, lock=p2p_lock)
591+
test_node.wait_until(lambda: "blocktxn" in test_node.last_message, timeout=10)
592592

593593
[tx.calc_sha256() for tx in block.vtx]
594594
with p2p_lock:
@@ -628,20 +628,20 @@ def test_compactblocks_not_at_tip(self, test_node):
628628
for _ in range(MAX_CMPCTBLOCK_DEPTH + 1):
629629
test_node.clear_block_announcement()
630630
new_blocks.append(node.generate(1)[0])
631-
wait_until(test_node.received_block_announcement, timeout=30, lock=p2p_lock)
631+
test_node.wait_until(test_node.received_block_announcement, timeout=30)
632632

633633
test_node.clear_block_announcement()
634634
test_node.send_message(msg_getdata([CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))]))
635-
wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30, lock=p2p_lock)
635+
test_node.wait_until(lambda: "cmpctblock" in test_node.last_message, timeout=30)
636636

637637
test_node.clear_block_announcement()
638638
node.generate(1)
639-
wait_until(test_node.received_block_announcement, timeout=30, lock=p2p_lock)
639+
test_node.wait_until(test_node.received_block_announcement, timeout=30)
640640
test_node.clear_block_announcement()
641641
with p2p_lock:
642642
test_node.last_message.pop("block", None)
643643
test_node.send_message(msg_getdata([CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))]))
644-
wait_until(lambda: "block" in test_node.last_message, timeout=30, lock=p2p_lock)
644+
test_node.wait_until(lambda: "block" in test_node.last_message, timeout=30)
645645
with p2p_lock:
646646
test_node.last_message["block"].block.calc_sha256()
647647
assert_equal(test_node.last_message["block"].block.sha256, int(new_blocks[0], 16))
@@ -689,7 +689,7 @@ def test_end_to_end_block_relay(self, listeners):
689689
node.submitblock(ToHex(block))
690690

691691
for l in listeners:
692-
wait_until(lambda: "cmpctblock" in l.last_message, timeout=30, lock=p2p_lock)
692+
l.wait_until(lambda: "cmpctblock" in l.last_message, timeout=30)
693693
with p2p_lock:
694694
for l in listeners:
695695
l.last_message["cmpctblock"].header_and_shortids.header.calc_sha256()

test/functional/p2p_disconnect_ban.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
assert_equal,
1111
assert_raises_rpc_error,
1212
connect_nodes,
13-
wait_until,
1413
)
1514

1615
class DisconnectBanTest(BitcoinTestFramework):
@@ -28,7 +27,7 @@ def run_test(self):
2827
self.log.info("setban: successfully ban single IP address")
2928
assert_equal(len(self.nodes[1].getpeerinfo()), 2) # node1 should have 2 connections to node0 at this point
3029
self.nodes[1].setban(subnet="127.0.0.1", command="add")
31-
wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 0, timeout=10)
30+
self.wait_until(lambda: len(self.nodes[1].getpeerinfo()) == 0, timeout=10)
3231
assert_equal(len(self.nodes[1].getpeerinfo()), 0) # all nodes must be disconnected at this point
3332
assert_equal(len(self.nodes[1].listbanned()), 1)
3433

@@ -95,7 +94,7 @@ def run_test(self):
9594
self.log.info("disconnectnode: successfully disconnect node by address")
9695
address1 = self.nodes[0].getpeerinfo()[0]['addr']
9796
self.nodes[0].disconnectnode(address=address1)
98-
wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1, timeout=10)
97+
self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1, timeout=10)
9998
assert not [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
10099

101100
self.log.info("disconnectnode: successfully reconnect node")
@@ -106,7 +105,7 @@ def run_test(self):
106105
self.log.info("disconnectnode: successfully disconnect node by node id")
107106
id1 = self.nodes[0].getpeerinfo()[0]['id']
108107
self.nodes[0].disconnectnode(nodeid=id1)
109-
wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1, timeout=10)
108+
self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 1, timeout=10)
110109
assert not [node for node in self.nodes[0].getpeerinfo() if node['id'] == id1]
111110

112111
if __name__ == '__main__':

test/functional/p2p_eviction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from test_framework.messages import CTransaction, FromHex, msg_pong, msg_tx
2020
from test_framework.p2p import P2PDataStore, P2PInterface
2121
from test_framework.test_framework import BitcoinTestFramework
22-
from test_framework.util import assert_equal, wait_until
22+
from test_framework.util import assert_equal
2323

2424

2525
class SlowP2PDataStore(P2PDataStore):
@@ -92,7 +92,7 @@ def run_test(self):
9292
for _ in range(8):
9393
fastpeer = node.add_p2p_connection(P2PInterface())
9494
current_peer += 1
95-
wait_until(lambda: "ping" in fastpeer.last_message, timeout=10)
95+
self.wait_until(lambda: "ping" in fastpeer.last_message, timeout=10)
9696

9797
# Make sure by asking the node what the actual min pings are
9898
peerinfo = node.getpeerinfo()

test/functional/p2p_feefilter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def on_inv(self, message):
3939

4040
def wait_for_invs_to_match(self, invs_expected):
4141
invs_expected.sort()
42-
self.wait_until(lambda: invs_expected == sorted(self.txinvs), timeout=60)
42+
self.wait_until(lambda: invs_expected == sorted(self.txinvs))
4343

4444
def clear_invs(self):
4545
with p2p_lock:

0 commit comments

Comments
 (0)