Skip to content

Commit 1b1c6dc

Browse files
TheCharlatanfurszy
andcommitted
test: Add functional test for continuing a reindex
Co-authored-by: furszy <[email protected]>
1 parent 201c1a9 commit 1b1c6dc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

test/functional/feature_reindex.py

+20
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,33 @@ def find_block(b, start):
7373
# All blocks should be accepted and processed.
7474
assert_equal(self.nodes[0].getblockcount(), 12)
7575

76+
def continue_reindex_after_shutdown(self):
77+
node = self.nodes[0]
78+
self.generate(node, 1500)
79+
80+
# Restart node with reindex and stop reindex as soon as it starts reindexing
81+
self.log.info("Restarting node while reindexing..")
82+
node.stop_node()
83+
with node.busy_wait_for_debug_log([b'initload thread start']):
84+
node.start(['-blockfilterindex', '-reindex'])
85+
node.wait_for_rpc_connection(wait_for_import=False)
86+
node.stop_node()
87+
88+
# Start node without the reindex flag and verify it does not wipe the indexes data again
89+
db_path = node.chain_path / 'indexes' / 'blockfilter' / 'basic' / 'db'
90+
with node.assert_debug_log(expected_msgs=[f'Opening LevelDB in {db_path}'], unexpected_msgs=[f'Wiping LevelDB in {db_path}']):
91+
node.start(['-blockfilterindex'])
92+
node.wait_for_rpc_connection(wait_for_import=False)
93+
node.stop_node()
94+
7695
def run_test(self):
7796
self.reindex(False)
7897
self.reindex(True)
7998
self.reindex(False)
8099
self.reindex(True)
81100

82101
self.out_of_order()
102+
self.continue_reindex_after_shutdown()
83103

84104

85105
if __name__ == '__main__':

test/functional/test_framework/test_node.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None
241241
if self.start_perf:
242242
self._start_perf()
243243

244-
def wait_for_rpc_connection(self):
244+
def wait_for_rpc_connection(self, *, wait_for_import=True):
245245
"""Sets up an RPC connection to the bitcoind process. Returns False if unable to connect."""
246246
# Poll at a rate of four times per second
247247
poll_per_s = 4
@@ -263,7 +263,7 @@ def wait_for_rpc_connection(self):
263263
)
264264
rpc.getblockcount()
265265
# If the call to getblockcount() succeeds then the RPC connection is up
266-
if self.version_is_at_least(190000):
266+
if self.version_is_at_least(190000) and wait_for_import:
267267
# getmempoolinfo.loaded is available since commit
268268
# bb8ae2c (version 0.19.0)
269269
self.wait_until(lambda: rpc.getmempoolinfo()['loaded'])

0 commit comments

Comments
 (0)