Skip to content

Commit fa63b82

Browse files
MarcoFalkedavidgumberg
andcommitted
test: generateblocks called by multiple threads
Co-Authored-By: David Gumberg <[email protected]>
1 parent fa62c8b commit fa63b82

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/functional/rpc_generate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2020-2022 The Bitcoin Core developers
2+
# Copyright (c) 2020-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test generate* RPCs."""
66

7+
from concurrent.futures import ThreadPoolExecutor
8+
79
from test_framework.test_framework import BitcoinTestFramework
810
from test_framework.wallet import MiniWallet
911
from test_framework.util import (
@@ -83,6 +85,13 @@ def test_generateblock(self):
8385
txid = block['tx'][1]
8486
assert_equal(node.getrawtransaction(txid=txid, verbose=False, blockhash=hash), rawtx)
8587

88+
# Ensure that generateblock can be called concurrently by many threads.
89+
self.log.info('Generate blocks in parallel')
90+
generate_50_blocks = lambda n: [n.generateblock(output=address, transactions=[]) for _ in range(50)]
91+
rpcs = [node.cli for _ in range(6)]
92+
with ThreadPoolExecutor(max_workers=len(rpcs)) as threads:
93+
list(threads.map(generate_50_blocks, rpcs))
94+
8695
self.log.info('Fail to generate block with out of order txs')
8796
txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
8897
utxo1 = miniwallet.get_utxo(txid=txid1)

0 commit comments

Comments
 (0)