mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 05:39:38 +02:00
test: feature_init, only init what's needed per perturbation/deletion round
Avoids initializing and syncing components not under test. This not only speeds up execution a bit but also helps isolate and debug issues more easily, as logs aren't flooded with unrelated details.
This commit is contained in:
@@ -47,9 +47,9 @@ class InitTest(BitcoinTestFramework):
|
|||||||
node.process.terminate()
|
node.process.terminate()
|
||||||
node.process.wait()
|
node.process.wait()
|
||||||
|
|
||||||
def start_expecting_error(err_fragment):
|
def start_expecting_error(err_fragment, args):
|
||||||
node.assert_start_raises_init_error(
|
node.assert_start_raises_init_error(
|
||||||
extra_args=['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1', '-checkblocks=200', '-checklevel=4'],
|
extra_args=args,
|
||||||
expected_msg=err_fragment,
|
expected_msg=err_fragment,
|
||||||
match=ErrorMatch.PARTIAL_REGEX,
|
match=ErrorMatch.PARTIAL_REGEX,
|
||||||
)
|
)
|
||||||
@@ -102,29 +102,76 @@ class InitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
self.log.info("Test startup errors after removing certain essential files")
|
self.log.info("Test startup errors after removing certain essential files")
|
||||||
|
|
||||||
files_to_delete = {
|
deletion_rounds = [
|
||||||
'blocks/index/*.ldb': 'Error opening block database.',
|
{
|
||||||
'chainstate/*.ldb': 'Error opening coins database.',
|
'filepath_glob': 'blocks/index/*.ldb',
|
||||||
'blocks/blk*.dat': 'Error loading block database.',
|
'error_message': 'Error opening block database.',
|
||||||
'indexes/txindex/MANIFEST*': 'LevelDB error: Corruption: CURRENT points to a non-existent file',
|
'startup_args': [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'chainstate/*.ldb',
|
||||||
|
'error_message': 'Error opening coins database.',
|
||||||
|
'startup_args': ['-checklevel=4'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'blocks/blk*.dat',
|
||||||
|
'error_message': 'Error loading block database.',
|
||||||
|
'startup_args': ['-checkblocks=200', '-checklevel=4'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'indexes/txindex/MANIFEST*',
|
||||||
|
'error_message': 'LevelDB error: Corruption: CURRENT points to a non-existent file',
|
||||||
|
'startup_args': ['-txindex=1'],
|
||||||
|
},
|
||||||
# Removing these files does not result in a startup error:
|
# Removing these files does not result in a startup error:
|
||||||
# 'indexes/blockfilter/basic/*.dat', 'indexes/blockfilter/basic/db/*.*', 'indexes/coinstats/db/*.*',
|
# 'indexes/blockfilter/basic/*.dat', 'indexes/blockfilter/basic/db/*.*', 'indexes/coinstats/db/*.*',
|
||||||
# 'indexes/txindex/*.log', 'indexes/txindex/CURRENT', 'indexes/txindex/LOCK'
|
# 'indexes/txindex/*.log', 'indexes/txindex/CURRENT', 'indexes/txindex/LOCK'
|
||||||
}
|
]
|
||||||
|
|
||||||
files_to_perturb = {
|
perturbation_rounds = [
|
||||||
'blocks/index/*.ldb': 'Error loading block database.',
|
{
|
||||||
'chainstate/*.ldb': 'Error opening coins database.',
|
'filepath_glob': 'blocks/index/*.ldb',
|
||||||
'blocks/blk*.dat': 'Corrupted block database detected.',
|
'error_message': 'Error loading block database.',
|
||||||
'indexes/blockfilter/basic/db/*.*': 'LevelDB error: Corruption',
|
'startup_args': [],
|
||||||
'indexes/coinstats/db/*.*': 'LevelDB error: Corruption',
|
},
|
||||||
'indexes/txindex/*.log': 'LevelDB error: Corruption',
|
{
|
||||||
'indexes/txindex/CURRENT': 'LevelDB error: Corruption',
|
'filepath_glob': 'chainstate/*.ldb',
|
||||||
|
'error_message': 'Error opening coins database.',
|
||||||
|
'startup_args': [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'blocks/blk*.dat',
|
||||||
|
'error_message': 'Corrupted block database detected.',
|
||||||
|
'startup_args': ['-checkblocks=200', '-checklevel=4'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'indexes/blockfilter/basic/db/*.*',
|
||||||
|
'error_message': 'LevelDB error: Corruption',
|
||||||
|
'startup_args': ['-blockfilterindex=1'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'indexes/coinstats/db/*.*',
|
||||||
|
'error_message': 'LevelDB error: Corruption',
|
||||||
|
'startup_args': ['-coinstatsindex=1'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'indexes/txindex/*.log',
|
||||||
|
'error_message': 'LevelDB error: Corruption',
|
||||||
|
'startup_args': ['-txindex=1'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'filepath_glob': 'indexes/txindex/CURRENT',
|
||||||
|
'error_message': 'LevelDB error: Corruption',
|
||||||
|
'startup_args': ['-txindex=1'],
|
||||||
|
},
|
||||||
# Perturbing these files does not result in a startup error:
|
# Perturbing these files does not result in a startup error:
|
||||||
# 'indexes/blockfilter/basic/*.dat', 'indexes/txindex/MANIFEST*', 'indexes/txindex/LOCK'
|
# 'indexes/blockfilter/basic/*.dat', 'indexes/txindex/MANIFEST*', 'indexes/txindex/LOCK'
|
||||||
}
|
]
|
||||||
|
|
||||||
for file_patt, err_fragment in files_to_delete.items():
|
for round_info in deletion_rounds:
|
||||||
|
file_patt = round_info['filepath_glob']
|
||||||
|
err_fragment = round_info['error_message']
|
||||||
|
startup_args = round_info['startup_args']
|
||||||
target_files = list(node.chain_path.glob(file_patt))
|
target_files = list(node.chain_path.glob(file_patt))
|
||||||
|
|
||||||
for target_file in target_files:
|
for target_file in target_files:
|
||||||
@@ -132,7 +179,7 @@ class InitTest(BitcoinTestFramework):
|
|||||||
bak_path = str(target_file) + ".bak"
|
bak_path = str(target_file) + ".bak"
|
||||||
target_file.rename(bak_path)
|
target_file.rename(bak_path)
|
||||||
|
|
||||||
start_expecting_error(err_fragment)
|
start_expecting_error(err_fragment, startup_args)
|
||||||
|
|
||||||
for target_file in target_files:
|
for target_file in target_files:
|
||||||
bak_path = str(target_file) + ".bak"
|
bak_path = str(target_file) + ".bak"
|
||||||
@@ -144,7 +191,11 @@ class InitTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
self.log.info("Test startup errors after perturbing certain essential files")
|
self.log.info("Test startup errors after perturbing certain essential files")
|
||||||
dirs = ["blocks", "chainstate", "indexes"]
|
dirs = ["blocks", "chainstate", "indexes"]
|
||||||
for file_patt, err_fragment in files_to_perturb.items():
|
for round_info in perturbation_rounds:
|
||||||
|
file_patt = round_info['filepath_glob']
|
||||||
|
err_fragment = round_info['error_message']
|
||||||
|
startup_args = round_info['startup_args']
|
||||||
|
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
shutil.copytree(node.chain_path / dir, node.chain_path / f"{dir}_bak")
|
shutil.copytree(node.chain_path / dir, node.chain_path / f"{dir}_bak")
|
||||||
target_files = list(node.chain_path.glob(file_patt))
|
target_files = list(node.chain_path.glob(file_patt))
|
||||||
@@ -158,7 +209,7 @@ class InitTest(BitcoinTestFramework):
|
|||||||
tf.seek(150)
|
tf.seek(150)
|
||||||
tf.write(b"1" * 200)
|
tf.write(b"1" * 200)
|
||||||
|
|
||||||
start_expecting_error(err_fragment)
|
start_expecting_error(err_fragment, startup_args)
|
||||||
|
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
shutil.rmtree(node.chain_path / dir)
|
shutil.rmtree(node.chain_path / dir)
|
||||||
|
|||||||
Reference in New Issue
Block a user