|
7 | 7 | Verify that a bitcoind node can load multiple wallet files
|
8 | 8 | """
|
9 | 9 | from decimal import Decimal
|
| 10 | +from threading import Thread |
10 | 11 | import os
|
11 | 12 | import shutil
|
12 | 13 | import time
|
13 | 14 |
|
| 15 | +from test_framework.authproxy import JSONRPCException |
14 | 16 | from test_framework.test_framework import BitcoinTestFramework
|
15 | 17 | from test_framework.test_node import ErrorMatch
|
16 | 18 | from test_framework.util import (
|
17 | 19 | assert_equal,
|
18 | 20 | assert_raises_rpc_error,
|
| 21 | + get_rpc_proxy, |
19 | 22 | )
|
20 | 23 |
|
21 | 24 | FEATURE_LATEST = 169900
|
22 | 25 |
|
| 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 | + |
23 | 40 |
|
24 | 41 | class MultiWalletTest(BitcoinTestFramework):
|
25 | 42 | def set_test_params(self):
|
@@ -212,6 +229,18 @@ def wallet_file(name):
|
212 | 229 | w2 = node.get_wallet_rpc(wallet_names[1])
|
213 | 230 | w2.getwalletinfo()
|
214 | 231 |
|
| 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 | + |
215 | 244 | self.log.info("Load remaining wallets")
|
216 | 245 | for wallet_name in wallet_names[2:]:
|
217 | 246 | loadwallet_name = self.nodes[0].loadwallet(wallet_name)
|
|
0 commit comments