Skip to content

Commit 8a45f57

Browse files
committed
Merge bitcoin/bitcoin#29335: test: Handle functional test disk-full error
357ad11 test: Handle functional test disk-full error (Brandon Odiwuor) Pull request description: Fixes: bitcoin/bitcoin#23099 Handle disk-full more gracefully in functional tests ACKs for top commit: itornaza: re-ACK 357ad11 achow101: reACK 357ad11 cbergqvist: reACK 357ad11. Looks good! tdb3: re ACK for 357ad11 Tree-SHA512: 9bb0d3fbe84600c88873b9f55d4b5d1443f79ec303467680c301be2b4879201387f203d9d1984169461f321037189b5e10a6a4b9d61750de638f072d2f95d77e
2 parents 573f631 + 357ad11 commit 8a45f57

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/functional/test_runner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929

3030
os.environ["REQUIRE_WALLET_TYPE_SET"] = "1"
3131

32+
# Minimum amount of space to run the tests.
33+
MIN_FREE_SPACE = 1.1 * 1024 * 1024 * 1024
34+
# Additional space to run an extra job.
35+
ADDITIONAL_SPACE_PER_JOB = 100 * 1024 * 1024
36+
# Minimum amount of space required for --nocleanup
37+
MIN_NO_CLEANUP_SPACE = 12 * 1024 * 1024 * 1024
38+
3239
# Formatting. Default colors to empty strings.
3340
DEFAULT, BOLD, GREEN, RED = ("", ""), ("", ""), ("", ""), ("", "")
3441
try:
@@ -426,6 +433,8 @@ def main():
426433
parser.add_argument('--tmpdirprefix', '-t', default=tempfile.gettempdir(), help="Root directory for datadirs")
427434
parser.add_argument('--failfast', '-F', action='store_true', help='stop execution after the first test failure')
428435
parser.add_argument('--filter', help='filter scripts to run by regular expression')
436+
parser.add_argument("--nocleanup", dest="nocleanup", default=False, action="store_true",
437+
help="Leave bitcoinds and test.* datadir on exit or error")
429438

430439

431440
args, unknown_args = parser.parse_known_args()
@@ -520,6 +529,13 @@ def main():
520529
subprocess.check_call([sys.executable, os.path.join(config["environment"]["SRCDIR"], 'test', 'functional', test_list[0].split()[0]), '-h'])
521530
sys.exit(0)
522531

532+
# Warn if there is not enough space on tmpdir to run the tests with --nocleanup
533+
if args.nocleanup:
534+
if shutil.disk_usage(tmpdir).free < MIN_NO_CLEANUP_SPACE:
535+
print(f"{BOLD[1]}WARNING!{BOLD[0]} There may be insufficient free space in {tmpdir} to run the functional test suite with --nocleanup. "
536+
f"A minimum of {MIN_NO_CLEANUP_SPACE // (1024 * 1024 * 1024)} GB of free space is required.")
537+
passon_args.append("--nocleanup")
538+
523539
check_script_list(src_dir=config["environment"]["SRCDIR"], fail_on_warn=args.ci)
524540
check_script_prefixes()
525541

@@ -556,6 +572,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
556572
if os.path.isdir(cache_dir):
557573
print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % (BOLD[1], BOLD[0], cache_dir))
558574

575+
# Warn if there is not enough space on the testing dir
576+
min_space = MIN_FREE_SPACE + (jobs - 1) * ADDITIONAL_SPACE_PER_JOB
577+
if shutil.disk_usage(tmpdir).free < min_space:
578+
print(f"{BOLD[1]}WARNING!{BOLD[0]} There may be insufficient free space in {tmpdir} to run the Bitcoin functional test suite. "
579+
f"Running the test suite with fewer than {min_space // (1024 * 1024)} MB of free space might cause tests to fail.")
559580

560581
tests_dir = src_dir + '/test/functional/'
561582
# This allows `test_runner.py` to work from an out-of-source build directory using a symlink,
@@ -625,6 +646,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
625646
logging.debug("Early exiting after test failure")
626647
break
627648

649+
if "[Errno 28] No space left on device" in stdout:
650+
sys.exit(f"Early exiting after test failure due to insuffient free space in {tmpdir}\n"
651+
f"Test execution data left in {tmpdir}.\n"
652+
f"Additional storage is needed to execute testing.")
653+
628654
print_results(test_results, max_len_name, (int(time.time() - start_time)))
629655

630656
if coverage:

0 commit comments

Comments
 (0)