Skip to content

Commit fac90e5

Browse files
author
MarcoFalke
committed
test: Check that the GUI interactive reindex works
1 parent faaadda commit fac90e5

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/common/args.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message
709709

710710
const std::vector<std::string> TEST_OPTIONS_DOC{
711711
"addrman (use deterministic addrman)",
712+
"reindex_after_failure_noninteractive_yes (When asked for a reindex after failure interactively, simulate as-if answered with 'yes')",
712713
"bip94 (enforce BIP94 consensus rules)",
713714
};
714715

src/init.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,10 +1737,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17371737
args);
17381738
if (status == ChainstateLoadStatus::FAILURE && !do_reindex && !ShutdownRequested(node)) {
17391739
// suggest a reindex
1740-
bool do_retry = uiInterface.ThreadSafeQuestion(
1740+
bool do_retry{HasTestOption(args, "reindex_after_failure_noninteractive_yes") ||
1741+
uiInterface.ThreadSafeQuestion(
17411742
error + Untranslated(".\n\n") + _("Do you want to rebuild the databases now?"),
17421743
error.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
1743-
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
1744+
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT)};
17441745
if (!do_retry) {
17451746
return false;
17461747
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test reindex works on init after a db load failure"""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import assert_equal
9+
import os
10+
import shutil
11+
12+
13+
class ReindexInitTest(BitcoinTestFramework):
14+
def set_test_params(self):
15+
self.num_nodes = 1
16+
17+
def run_test(self):
18+
node = self.nodes[0]
19+
self.stop_nodes()
20+
21+
self.log.info("Removing the block index leads to init error")
22+
shutil.rmtree(node.blocks_path / "index")
23+
node.assert_start_raises_init_error(
24+
expected_msg=f": Error initializing block database.{os.linesep}"
25+
"Please restart with -reindex or -reindex-chainstate to recover.",
26+
)
27+
28+
self.log.info("Allowing the reindex should work fine")
29+
self.start_node(0, extra_args=["-test=reindex_after_failure_noninteractive_yes"])
30+
assert_equal(node.getblockcount(), 200)
31+
32+
33+
if __name__ == "__main__":
34+
ReindexInitTest(__file__).main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
'p2p_leak.py',
290290
'wallet_encryption.py',
291291
'feature_dersig.py',
292+
'feature_reindex_init.py',
292293
'feature_cltv.py',
293294
'rpc_uptime.py',
294295
'feature_discover.py',

0 commit comments

Comments
 (0)