Skip to content

Commit

Permalink
Merge #29335: test: Handle functional test disk-full error
Browse files Browse the repository at this point in the history
357ad11 test: Handle functional test disk-full error (Brandon Odiwuor)

Pull request description:

  Fixes: #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
  • Loading branch information
achow101 committed May 8, 2024
2 parents 573f631 + 357ad11 commit 8a45f57
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/functional/test_runner.py
Expand Up @@ -29,6 +29,13 @@

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

# Minimum amount of space to run the tests.
MIN_FREE_SPACE = 1.1 * 1024 * 1024 * 1024
# Additional space to run an extra job.
ADDITIONAL_SPACE_PER_JOB = 100 * 1024 * 1024
# Minimum amount of space required for --nocleanup
MIN_NO_CLEANUP_SPACE = 12 * 1024 * 1024 * 1024

# Formatting. Default colors to empty strings.
DEFAULT, BOLD, GREEN, RED = ("", ""), ("", ""), ("", ""), ("", "")
try:
Expand Down Expand Up @@ -426,6 +433,8 @@ def main():
parser.add_argument('--tmpdirprefix', '-t', default=tempfile.gettempdir(), help="Root directory for datadirs")
parser.add_argument('--failfast', '-F', action='store_true', help='stop execution after the first test failure')
parser.add_argument('--filter', help='filter scripts to run by regular expression')
parser.add_argument("--nocleanup", dest="nocleanup", default=False, action="store_true",
help="Leave bitcoinds and test.* datadir on exit or error")


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

# Warn if there is not enough space on tmpdir to run the tests with --nocleanup
if args.nocleanup:
if shutil.disk_usage(tmpdir).free < MIN_NO_CLEANUP_SPACE:
print(f"{BOLD[1]}WARNING!{BOLD[0]} There may be insufficient free space in {tmpdir} to run the functional test suite with --nocleanup. "
f"A minimum of {MIN_NO_CLEANUP_SPACE // (1024 * 1024 * 1024)} GB of free space is required.")
passon_args.append("--nocleanup")

check_script_list(src_dir=config["environment"]["SRCDIR"], fail_on_warn=args.ci)
check_script_prefixes()

Expand Down Expand Up @@ -556,6 +572,11 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=
if os.path.isdir(cache_dir):
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))

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

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

if "[Errno 28] No space left on device" in stdout:
sys.exit(f"Early exiting after test failure due to insuffient free space in {tmpdir}\n"
f"Test execution data left in {tmpdir}.\n"
f"Additional storage is needed to execute testing.")

print_results(test_results, max_len_name, (int(time.time() - start_time)))

if coverage:
Expand Down

0 comments on commit 8a45f57

Please sign in to comment.