Skip to content

Commit 740cff5

Browse files
committed
Merge #8482: [qa] Use single cache dir for chains
fad8cf6 [qa] Use single cache dir for chains (MarcoFalke) fa2d68f [qa] Adjust timeouts for micro-optimization of run time (MarcoFalke) fae596f [qa] Sort scripts by time for pull_tester and don't overwrite setup_chain (MarcoFalke)
2 parents 29496fc + fad8cf6 commit 740cff5

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ linux-build
103103
win32-build
104104
qa/pull-tester/run-bitcoind-for-test.sh
105105
qa/pull-tester/tests_config.py
106-
qa/pull-tester/cache/*
107106
qa/pull-tester/test.*/*
108107
qa/tmp
109-
cache/
108+
qa/cache/*
110109
share/BitcoindComparisonTool.jar
111110

112111
!src/leveldb*/Makefile

qa/pull-tester/rpc-tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
'receivedby.py',
113113
'mempool_resurrect_test.py',
114114
'txn_doublespend.py --mineblock',
115+
'p2p-segwit.py',
116+
'segwit.py',
115117
'txn_clone.py',
116118
'getchaintips.py',
117119
'rawtransactions.py',
@@ -133,13 +135,12 @@
133135
'disablewallet.py',
134136
'sendheaders.py',
135137
'keypool.py',
138+
'p2p-mempool.py',
136139
'prioritise_transaction.py',
137140
'invalidblockrequest.py',
138141
'invalidtxrequest.py',
139142
'abandonconflict.py',
140143
'p2p-versionbits-warning.py',
141-
'p2p-segwit.py',
142-
'segwit.py',
143144
'importprunedfunds.py',
144145
'signmessages.py',
145146
'p2p-compactblocks.py',
@@ -194,6 +195,7 @@ def runtests():
194195
coverage = RPCCoverage()
195196
print("Initializing coverage directory at %s\n" % coverage.dir)
196197
flags = ["--srcdir=%s/src" % BUILDDIR] + passon_args
198+
flags.append("--cachedir=%s/qa/cache" % BUILDDIR)
197199
if coverage:
198200
flags.append(coverage.flag)
199201

qa/rpc-tests/p2p-mempool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ def send_mempool(self):
7272
self.send_message(msg_mempool())
7373

7474
class P2PMempoolTests(BitcoinTestFramework):
75-
def setup_chain(self):
76-
initialize_chain_clean(self.options.tmpdir, 2)
75+
76+
def __init__(self):
77+
super().__init__()
78+
self.setup_clean_chain = True
79+
self.num_nodes = 2
7780

7881
def setup_network(self):
7982
# Start a node with maxuploadtarget of 200 MB (/24h)

qa/rpc-tests/p2p-segwit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ def __init__(self, sha256, n, nValue):
168168

169169

170170
class SegWitTest(BitcoinTestFramework):
171-
def setup_chain(self):
172-
initialize_chain_clean(self.options.tmpdir, 3)
171+
172+
def __init__(self):
173+
super().__init__()
174+
self.setup_clean_chain = True
175+
self.num_nodes = 3
173176

174177
def add_options(self, parser):
175178
parser.add_option("--oldbinary", dest="oldbinary",

qa/rpc-tests/segwit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def find_unspent(node, min_value):
7676

7777
class SegWitTest(BitcoinTestFramework):
7878

79-
def setup_chain(self):
80-
print("Initializing test directory "+self.options.tmpdir)
81-
initialize_chain_clean(self.options.tmpdir, 3)
79+
def __init__(self):
80+
super().__init__()
81+
self.setup_clean_chain = True
82+
self.num_nodes = 3
8283

8384
def setup_network(self):
8485
self.nodes = []

qa/rpc-tests/test_framework/test_framework.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def setup_chain(self):
4848
if self.setup_clean_chain:
4949
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
5050
else:
51-
initialize_chain(self.options.tmpdir, self.num_nodes)
51+
initialize_chain(self.options.tmpdir, self.num_nodes, self.options.cachedir)
5252

5353
def stop_node(self, num_node):
5454
stop_node(self.nodes[num_node], num_node)
@@ -112,6 +112,8 @@ def main(self):
112112
help="Don't stop bitcoinds after the test execution")
113113
parser.add_option("--srcdir", dest="srcdir", default=os.path.normpath(os.path.dirname(os.path.realpath(__file__))+"/../../../src"),
114114
help="Source directory containing bitcoind/bitcoin-cli (default: %default)")
115+
parser.add_option("--cachedir", dest="cachedir", default=os.path.normpath(os.path.dirname(os.path.realpath(__file__))+"/../../cache"),
116+
help="Directory for caching pregenerated datadirs")
115117
parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"),
116118
help="Root directory for datadirs")
117119
parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true",

qa/rpc-tests/test_framework/util.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def hex_str_to_bytes(hex_str):
121121
def str_to_b64str(string):
122122
return b64encode(string.encode('utf-8')).decode('ascii')
123123

124-
def sync_blocks(rpc_connections, wait=1, timeout=60):
124+
def sync_blocks(rpc_connections, wait=0.125, timeout=60):
125125
"""
126126
Wait until everybody has the same tip
127127
"""
@@ -133,7 +133,7 @@ def sync_blocks(rpc_connections, wait=1, timeout=60):
133133
timeout -= wait
134134
raise AssertionError("Block sync failed")
135135

136-
def sync_mempools(rpc_connections, wait=1, timeout=60):
136+
def sync_mempools(rpc_connections, wait=0.5, timeout=60):
137137
"""
138138
Wait until everybody has the same transactions in their memory
139139
pools
@@ -201,7 +201,7 @@ def wait_for_bitcoind_start(process, url, i):
201201
raise # unkown JSON RPC exception
202202
time.sleep(0.25)
203203

204-
def initialize_chain(test_dir, num_nodes):
204+
def initialize_chain(test_dir, num_nodes, cachedir):
205205
"""
206206
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
207207
Afterward, create num_nodes copies from the cache
@@ -210,20 +210,20 @@ def initialize_chain(test_dir, num_nodes):
210210
assert num_nodes <= MAX_NODES
211211
create_cache = False
212212
for i in range(MAX_NODES):
213-
if not os.path.isdir(os.path.join('cache', 'node'+str(i))):
213+
if not os.path.isdir(os.path.join(cachedir, 'node'+str(i))):
214214
create_cache = True
215215
break
216216

217217
if create_cache:
218218

219219
#find and delete old cache directories if any exist
220220
for i in range(MAX_NODES):
221-
if os.path.isdir(os.path.join("cache","node"+str(i))):
222-
shutil.rmtree(os.path.join("cache","node"+str(i)))
221+
if os.path.isdir(os.path.join(cachedir,"node"+str(i))):
222+
shutil.rmtree(os.path.join(cachedir,"node"+str(i)))
223223

224224
# Create cache directories, run bitcoinds:
225225
for i in range(MAX_NODES):
226-
datadir=initialize_datadir("cache", i)
226+
datadir=initialize_datadir(cachedir, i)
227227
args = [ os.getenv("BITCOIND", "bitcoind"), "-server", "-keypool=1", "-datadir="+datadir, "-discover=0" ]
228228
if i > 0:
229229
args.append("-connect=127.0.0.1:"+str(p2p_port(0)))
@@ -265,13 +265,13 @@ def initialize_chain(test_dir, num_nodes):
265265
wait_bitcoinds()
266266
disable_mocktime()
267267
for i in range(MAX_NODES):
268-
os.remove(log_filename("cache", i, "debug.log"))
269-
os.remove(log_filename("cache", i, "db.log"))
270-
os.remove(log_filename("cache", i, "peers.dat"))
271-
os.remove(log_filename("cache", i, "fee_estimates.dat"))
268+
os.remove(log_filename(cachedir, i, "debug.log"))
269+
os.remove(log_filename(cachedir, i, "db.log"))
270+
os.remove(log_filename(cachedir, i, "peers.dat"))
271+
os.remove(log_filename(cachedir, i, "fee_estimates.dat"))
272272

273273
for i in range(num_nodes):
274-
from_dir = os.path.join("cache", "node"+str(i))
274+
from_dir = os.path.join(cachedir, "node"+str(i))
275275
to_dir = os.path.join(test_dir, "node"+str(i))
276276
shutil.copytree(from_dir, to_dir)
277277
initialize_datadir(test_dir, i) # Overwrite port/rpcport in bitcoin.conf

0 commit comments

Comments
 (0)