Skip to content

Commit 891784c

Browse files
seditedfurszy
andcommitted
test: Add functional test for continuing a reindex
Co-authored-by: furszy <[email protected]>
1 parent 9de8b26 commit 891784c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

test/functional/feature_reindex.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,35 @@ 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+
self.log.info("Wait until block filter index is synced..")
80+
self.restart_node(0, ['-blockfilterindex'])
81+
82+
# Restart node with reindex and stop reindex as soon as it starts reindexing
83+
self.log.info("Restarting node while reindexing..")
84+
node.stop_node()
85+
with node.busy_wait_for_debug_log([b'initload thread start']):
86+
node.start(['-blockfilterindex', '-reindex'])
87+
node.wait_for_rpc_connection(wait_for_import=False)
88+
node.stop_node()
89+
90+
# Start node without the reindex flag and verify it does not wipe the indexes data again
91+
db_path = node.datadir_path / 'regtest'/ 'indexes' / 'blockfilter' / 'basic' / 'db'
92+
with node.assert_debug_log(expected_msgs=[f'Opening LevelDB in {db_path}'], unexpected_msgs=[f'Wiping LevelDB in {db_path}']):
93+
node.start(['-blockfilterindex'])
94+
node.wait_for_rpc_connection(wait_for_import=False)
95+
node.stop_node()
96+
7697
def run_test(self):
7798
self.reindex(False)
7899
self.reindex(True)
79100
self.reindex(False)
80101
self.reindex(True)
81102

82103
self.out_of_order()
104+
self.continue_reindex_after_shutdown()
83105

84106

85107
if __name__ == '__main__':

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
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)