Skip to content

Commit 9b009fa

Browse files
committed
qa: Test concurrent wallet loading
1 parent b9971ae commit 9b009fa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/functional/wallet_multiwallet.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,36 @@
77
Verify that a bitcoind node can load multiple wallet files
88
"""
99
from decimal import Decimal
10+
from threading import Thread
1011
import os
1112
import shutil
1213
import time
1314

15+
from test_framework.authproxy import JSONRPCException
1416
from test_framework.test_framework import BitcoinTestFramework
1517
from test_framework.test_node import ErrorMatch
1618
from test_framework.util import (
1719
assert_equal,
1820
assert_raises_rpc_error,
21+
get_rpc_proxy,
1922
)
2023

2124
FEATURE_LATEST = 169900
2225

26+
got_loading_error = False
27+
def test_load_unload(node, name):
28+
global got_loading_error
29+
for i in range(10):
30+
if got_loading_error:
31+
return
32+
try:
33+
node.loadwallet(name)
34+
node.unloadwallet(name)
35+
except JSONRPCException as e:
36+
if e.error['code'] == -4 and 'Wallet already being loading' in e.error['message']:
37+
got_loading_error = True
38+
return
39+
2340

2441
class MultiWalletTest(BitcoinTestFramework):
2542
def set_test_params(self):
@@ -212,6 +229,18 @@ def wallet_file(name):
212229
w2 = node.get_wallet_rpc(wallet_names[1])
213230
w2.getwalletinfo()
214231

232+
self.log.info("Concurrent wallet loading")
233+
threads = []
234+
for _ in range(3):
235+
n = node.cli if self.options.usecli else get_rpc_proxy(node.url, 1, timeout=600, coveragedir=node.coverage_dir)
236+
t = Thread(target=test_load_unload, args=(n, wallet_names[2], ))
237+
t.start()
238+
threads.append(t)
239+
for t in threads:
240+
t.join()
241+
global got_loading_error
242+
assert_equal(got_loading_error, True)
243+
215244
self.log.info("Load remaining wallets")
216245
for wallet_name in wallet_names[2:]:
217246
loadwallet_name = self.nodes[0].loadwallet(wallet_name)

0 commit comments

Comments
 (0)