aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/example_test.py3
-rwxr-xr-xtest/functional/feature_backwards_compatibility.py6
-rwxr-xr-xtest/functional/feature_versionbits_warning.py4
-rwxr-xr-xtest/functional/mempool_compatibility.py2
-rwxr-xr-xtest/functional/p2p_leak.py8
-rwxr-xr-xtest/functional/test_framework/p2p.py8
-rwxr-xr-xtest/functional/test_framework/test_framework.py6
-rwxr-xr-xtest/functional/test_framework/test_node.py8
-rw-r--r--test/functional/test_framework/util.py16
-rwxr-xr-xtest/functional/wallet_upgradewallet.py2
10 files changed, 32 insertions, 31 deletions
diff --git a/test/functional/example_test.py b/test/functional/example_test.py
index 1832043989..083deb6460 100755
--- a/test/functional/example_test.py
+++ b/test/functional/example_test.py
@@ -207,10 +207,11 @@ class ExampleTest(BitcoinTestFramework):
self.log.info("Check that each block was received only once")
# The network thread uses a global lock on data access to the P2PConnection objects when sending and receiving
# messages. The test thread should acquire the global lock before accessing any P2PConnection data to avoid locking
- # and synchronization issues. Note wait_until() acquires this global lock when testing the predicate.
+ # and synchronization issues. Note p2p.wait_until() acquires this global lock internally when testing the predicate.
with p2p_lock:
for block in self.nodes[2].p2p.block_receive_map.values():
assert_equal(block, 1)
+
if __name__ == '__main__':
ExampleTest().main()
diff --git a/test/functional/feature_backwards_compatibility.py b/test/functional/feature_backwards_compatibility.py
index 126c9fe929..dd17e888f9 100755
--- a/test/functional/feature_backwards_compatibility.py
+++ b/test/functional/feature_backwards_compatibility.py
@@ -6,7 +6,7 @@
Test various backwards compatibility scenarios. Download the previous node binaries:
-test/get_previous_releases.py -b v0.19.1 v0.18.1 v0.17.1 v0.16.3 v0.15.2
+test/get_previous_releases.py -b v0.19.1 v0.18.1 v0.17.2 v0.16.3 v0.15.2
v0.15.2 is not required by this test, but it is used in wallet_upgradewallet.py.
Due to a hardfork in regtest, it can't be used to sync nodes.
@@ -40,7 +40,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # Pre-release: use to receive coins, swap wallets, etc
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.19.1
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.18.1
- ["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.17.1
+ ["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.17.2
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.16.3
]
@@ -54,7 +54,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
None,
190100,
180100,
- 170100,
+ 170200,
160300,
])
diff --git a/test/functional/feature_versionbits_warning.py b/test/functional/feature_versionbits_warning.py
index e045adac32..e1016e1581 100755
--- a/test/functional/feature_versionbits_warning.py
+++ b/test/functional/feature_versionbits_warning.py
@@ -12,7 +12,7 @@ import re
from test_framework.blocktools import create_block, create_coinbase
from test_framework.messages import msg_block
-from test_framework.p2p import p2p_lock, P2PInterface
+from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
VB_PERIOD = 144 # versionbits period length for regtest
@@ -90,7 +90,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
# Generating one block guarantees that we'll get out of IBD
node.generatetoaddress(1, node_deterministic_address)
- self.wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=p2p_lock)
+ self.wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'])
# Generating one more block will be enough to generate an error.
node.generatetoaddress(1, node_deterministic_address)
# Check that get*info() shows the versionbits unknown rules warning
diff --git a/test/functional/mempool_compatibility.py b/test/functional/mempool_compatibility.py
index 75ca8d3236..ad29d389e2 100755
--- a/test/functional/mempool_compatibility.py
+++ b/test/functional/mempool_compatibility.py
@@ -8,7 +8,7 @@ NOTE: The test is designed to prevent cases when compatibility is broken acciden
In case we need to break mempool compatibility we can continue to use the test by just bumping the version number.
Download node binaries:
-test/get_previous_releases.py -b v0.19.1 v0.18.1 v0.17.1 v0.16.3 v0.15.2
+test/get_previous_releases.py -b v0.19.1 v0.18.1 v0.17.2 v0.16.3 v0.15.2
Only v0.15.2 is required by this test. The rest is used in other backwards compatibility tests.
"""
diff --git a/test/functional/p2p_leak.py b/test/functional/p2p_leak.py
index 4978aa3845..4b32d60db0 100755
--- a/test/functional/p2p_leak.py
+++ b/test/functional/p2p_leak.py
@@ -17,7 +17,7 @@ from test_framework.messages import (
msg_ping,
msg_version,
)
-from test_framework.p2p import p2p_lock, P2PInterface
+from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
@@ -113,9 +113,9 @@ class P2PLeakTest(BitcoinTestFramework):
# verack, since we never sent one
no_verack_idle_peer.wait_for_verack()
- self.wait_until(lambda: no_version_disconnect_peer.ever_connected, timeout=10, lock=p2p_lock)
- self.wait_until(lambda: no_version_idle_peer.ever_connected, timeout=10, lock=p2p_lock)
- self.wait_until(lambda: no_verack_idle_peer.version_received, timeout=10, lock=p2p_lock)
+ no_version_disconnect_peer.wait_until(lambda: no_version_disconnect_peer.ever_connected, check_connected=False)
+ no_version_idle_peer.wait_until(lambda: no_version_idle_peer.ever_connected)
+ no_verack_idle_peer.wait_until(lambda: no_verack_idle_peer.version_received)
# Mine a block and make sure that it's not sent to the connected peers
self.nodes[0].generate(nblocks=1)
diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
index 57c77e60b5..963a507f53 100755
--- a/test/functional/test_framework/p2p.py
+++ b/test/functional/test_framework/p2p.py
@@ -69,7 +69,7 @@ from test_framework.messages import (
NODE_WITNESS,
sha256,
)
-from test_framework.util import wait_until
+from test_framework.util import wait_until_helper
logger = logging.getLogger("TestFramework.p2p")
@@ -293,7 +293,7 @@ class P2PInterface(P2PConnection):
# Track the most recent message of each type.
# To wait for a message to be received, pop that message from
- # this and use wait_until.
+ # this and use self.wait_until.
self.last_message = {}
# A count of the number of ping messages we've sent to the node
@@ -398,7 +398,7 @@ class P2PInterface(P2PConnection):
assert self.is_connected
return test_function_in()
- wait_until(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor)
+ wait_until_helper(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor)
def wait_for_disconnect(self, timeout=60):
test_function = lambda: not self.is_connected
@@ -522,7 +522,7 @@ class NetworkThread(threading.Thread):
def close(self, timeout=10):
"""Close the connections and network event loop."""
self.network_event_loop.call_soon_threadsafe(self.network_event_loop.stop)
- wait_until(lambda: not self.network_event_loop.is_running(), timeout=timeout)
+ wait_until_helper(lambda: not self.network_event_loop.is_running(), timeout=timeout)
self.network_event_loop.close()
self.join(timeout)
# Safe to remove event loop.
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 2a60f8e0c1..f41f5129b8 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -31,7 +31,7 @@ from .util import (
disconnect_nodes,
get_datadir_path,
initialize_datadir,
- wait_until,
+ wait_until_helper,
)
@@ -603,8 +603,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
self.sync_blocks(nodes)
self.sync_mempools(nodes)
- def wait_until(self, test_function, timeout=60, lock=None):
- return wait_until(test_function, timeout=timeout, lock=lock, timeout_factor=self.options.timeout_factor)
+ def wait_until(self, test_function, timeout=60):
+ return wait_until_helper(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor)
# Private helper methods. These should not be accessed by the subclass test scripts.
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 5c7a883c43..d034986821 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -31,7 +31,7 @@ from .util import (
get_auth_cookie,
get_rpc_proxy,
rpc_url,
- wait_until,
+ wait_until_helper,
p2p_port,
EncodeDecimal,
)
@@ -231,7 +231,7 @@ class TestNode():
if self.version_is_at_least(190000):
# getmempoolinfo.loaded is available since commit
# bb8ae2c (version 0.19.0)
- wait_until(lambda: rpc.getmempoolinfo()['loaded'])
+ wait_until_helper(lambda: rpc.getmempoolinfo()['loaded'], timeout_factor=self.timeout_factor)
# Wait for the node to finish reindex, block import, and
# loading the mempool. Usually importing happens fast or
# even "immediate" when the node is started. However, there
@@ -359,7 +359,7 @@ class TestNode():
return True
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
- wait_until(self.is_node_stopped, timeout=timeout, timeout_factor=self.timeout_factor)
+ wait_until_helper(self.is_node_stopped, timeout=timeout, timeout_factor=self.timeout_factor)
@contextlib.contextmanager
def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
@@ -560,7 +560,7 @@ class TestNode():
for p in self.p2ps:
p.peer_disconnect()
del self.p2ps[:]
- wait_until(lambda: self.num_test_p2p_connections() == 0)
+ wait_until_helper(lambda: self.num_test_p2p_connections() == 0, timeout_factor=self.timeout_factor)
class TestNodeCLIAttr:
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index b9c7e89ac8..af7f0b62f4 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -226,14 +226,14 @@ def satoshi_round(amount):
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
-def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0):
+def wait_until_helper(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0):
"""Sleep until the predicate resolves to be True.
Warning: Note that this method is not recommended to be used in tests as it is
- not aware of the context of the test framework. Using `wait_until()` counterpart
- from `BitcoinTestFramework` or `P2PInterface` class ensures an understandable
- amount of timeout and a common shared timeout_factor. Furthermore, `wait_until()`
- from `P2PInterface` class in `mininode.py` has a preset lock.
+ not aware of the context of the test framework. Using the `wait_until()` members
+ from `BitcoinTestFramework` or `P2PInterface` class ensures the timeout is
+ properly scaled. Furthermore, `wait_until()` from `P2PInterface` class in
+ `p2p.py` has a preset lock.
"""
if attempts == float('inf') and timeout == float('inf'):
timeout = 60
@@ -438,7 +438,7 @@ def disconnect_nodes(from_connection, node_num):
raise
# wait to disconnect
- wait_until(lambda: not get_peer_ids(), timeout=5)
+ wait_until_helper(lambda: not get_peer_ids(), timeout=5)
def connect_nodes(from_connection, node_num):
@@ -449,8 +449,8 @@ def connect_nodes(from_connection, node_num):
# See comments in net_processing:
# * Must have a version message before anything else
# * Must have a verack message before anything else
- wait_until(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
- wait_until(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
+ wait_until_helper(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
+ wait_until_helper(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
# Transaction/Block functions
diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py
index f3d6e74829..69aa603c6b 100755
--- a/test/functional/wallet_upgradewallet.py
+++ b/test/functional/wallet_upgradewallet.py
@@ -6,7 +6,7 @@
Test upgradewallet RPC. Download node binaries:
-test/get_previous_releases.py -b v0.19.1 v0.18.1 v0.17.1 v0.16.3 v0.15.2
+test/get_previous_releases.py -b v0.19.1 v0.18.1 v0.17.2 v0.16.3 v0.15.2
Only v0.15.2 and v0.16.3 are required by this test. The others are used in feature_backwards_compatibility.py
"""