Skip to content

Commit 357ad11

Browse files
test: Handle functional test disk-full error
1 parent a46065e commit 357ad11

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:
@@ -424,6 +431,8 @@ def main():
424431
parser.add_argument('--tmpdirprefix', '-t', default=tempfile.gettempdir(), help="Root directory for datadirs")
425432
parser.add_argument('--failfast', '-F', action='store_true', help='stop execution after the first test failure')
426433
parser.add_argument('--filter', help='filter scripts to run by regular expression')
434+
parser.add_argument("--nocleanup", dest="nocleanup", default=False, action="store_true",
435+
help="Leave bitcoinds and test.* datadir on exit or error")
427436

428437

429438
args, unknown_args = parser.parse_known_args()
@@ -518,6 +527,13 @@ def main():
518527
subprocess.check_call([sys.executable, os.path.join(config["environment"]["SRCDIR"], 'test', 'functional', test_list[0].split()[0]), '-h'])
519528
sys.exit(0)
520529

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

@@ -554,6 +570,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
554570
if os.path.isdir(cache_dir):
555571
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))
556572

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

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

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

628654
if coverage:

0 commit comments

Comments
 (0)