0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-13 11:25:02 -05:00

test: Replace threading with concurrent.futures

This commit is contained in:
MarcoFalke 2023-03-21 09:47:02 +01:00
parent 40e1c4d402
commit fa0696e786
No known key found for this signature in database
2 changed files with 30 additions and 32 deletions

View file

@ -15,7 +15,7 @@ variants.
- `test_address()` is called to call getaddressinfo for an address on node1 - `test_address()` is called to call getaddressinfo for an address on node1
and test the values returned.""" and test the values returned."""
import threading import concurrent.futures
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.blocktools import COINBASE_MATURITY from test_framework.blocktools import COINBASE_MATURITY
@ -691,25 +691,24 @@ class ImportDescriptorsTest(BitcoinTestFramework):
descriptor["next_index"] = 0 descriptor["next_index"] = 0
encrypted_wallet.walletpassphrase("passphrase", 99999) encrypted_wallet.walletpassphrase("passphrase", 99999)
t = threading.Thread(target=encrypted_wallet.importdescriptors, args=([descriptor],)) with concurrent.futures.ThreadPoolExecutor(max_workers=1) as thread:
with self.nodes[0].assert_debug_log(expected_msgs=["Rescan started from block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206... (slow variant inspecting all blocks)"], timeout=5):
importing = thread.submit(encrypted_wallet.importdescriptors, requests=[descriptor])
with self.nodes[0].assert_debug_log(expected_msgs=[f'Rescan started from block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206... (slow variant inspecting all blocks)'], timeout=5): # Set the passphrase timeout to 1 to test that the wallet remains unlocked during the rescan
t.start() self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletpassphrase("passphrase", 1)
# Set the passphrase timeout to 1 to test that the wallet remains unlocked during the rescan try:
self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletpassphrase("passphrase", 1) self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletlock()
except JSONRPCException as e:
assert e.error["code"] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet." in e.error["message"]
try: try:
self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletlock() self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletpassphrasechange("passphrase", "newpassphrase")
except JSONRPCException as e: except JSONRPCException as e:
assert e.error['code'] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet." in e.error['message'] assert e.error["code"] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase." in e.error["message"]
try: assert_equal(importing.result(), [{"success": True}])
self.nodes[0].cli("-rpcwallet=encrypted_wallet").walletpassphrasechange("passphrase", "newpassphrase")
except JSONRPCException as e:
assert e.error['code'] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase." in e.error['message']
t.join()
assert_equal(temp_wallet.getbalance(), encrypted_wallet.getbalance()) assert_equal(temp_wallet.getbalance(), encrypted_wallet.getbalance())

View file

@ -5,7 +5,7 @@
"""Test transaction time during old block rescanning """Test transaction time during old block rescanning
""" """
import threading import concurrent.futures
import time import time
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
@ -201,25 +201,24 @@ class TransactionTimeRescanTest(BitcoinTestFramework):
encrypted_wallet.walletpassphrase("passphrase", 99999) encrypted_wallet.walletpassphrase("passphrase", 99999)
encrypted_wallet.sethdseed(seed=hd_seed) encrypted_wallet.sethdseed(seed=hd_seed)
t = threading.Thread(target=encrypted_wallet.rescanblockchain) with concurrent.futures.ThreadPoolExecutor(max_workers=1) as thread:
with minernode.assert_debug_log(expected_msgs=["Rescan started from block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206... (slow variant inspecting all blocks)"], timeout=5):
rescanning = thread.submit(encrypted_wallet.rescanblockchain)
with minernode.assert_debug_log(expected_msgs=[f'Rescan started from block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206... (slow variant inspecting all blocks)'], timeout=5): # set the passphrase timeout to 1 to test that the wallet remains unlocked during the rescan
t.start() minernode.cli("-rpcwallet=encrypted_wallet").walletpassphrase("passphrase", 1)
# set the passphrase timeout to 1 to test that the wallet remains unlocked during the rescan try:
minernode.cli("-rpcwallet=encrypted_wallet").walletpassphrase("passphrase", 1) minernode.cli("-rpcwallet=encrypted_wallet").walletlock()
except JSONRPCException as e:
assert e.error["code"] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet." in e.error["message"]
try: try:
minernode.cli("-rpcwallet=encrypted_wallet").walletlock() minernode.cli("-rpcwallet=encrypted_wallet").walletpassphrasechange("passphrase", "newpassphrase")
except JSONRPCException as e: except JSONRPCException as e:
assert e.error['code'] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet." in e.error['message'] assert e.error["code"] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase." in e.error["message"]
try: assert_equal(rescanning.result(), {"start_height": 0, "stop_height": 803})
minernode.cli("-rpcwallet=encrypted_wallet").walletpassphrasechange("passphrase", "newpassphrase")
except JSONRPCException as e:
assert e.error['code'] == -4 and "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase." in e.error['message']
t.join()
assert_equal(encrypted_wallet.getbalance(), temp_wallet.getbalance()) assert_equal(encrypted_wallet.getbalance(), temp_wallet.getbalance())