Skip to content

Commit

Permalink
Partial Merge bitcoin#11789
Browse files Browse the repository at this point in the history
  • Loading branch information
John Newbery authored and PastaPastaPasta committed Jun 13, 2020
1 parent 1cb48b2 commit 2a4d173
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
27 changes: 7 additions & 20 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Base class for RPC testing."""

import copy
from collections import deque
from enum import Enum
import logging
import optparse
Expand Down Expand Up @@ -174,32 +174,19 @@ def main(self):
shutil.rmtree(self.options.tmpdir)
else:
self.log.warning("Not cleaning up dir %s" % self.options.tmpdir)
if os.getenv("PYTHON_DEBUG", ""):
# Dump the end of the debug logs, to aid in debugging rare
# travis failures.
import glob
filenames = [self.options.tmpdir + "/test_framework.log"]
filenames += glob.glob(self.options.tmpdir + "/node*/regtest/debug.log")
MAX_LINES_TO_PRINT = 1000
for fn in filenames:
try:
with open(fn, 'r') as f:
print("From", fn, ":")
print("".join(deque(f, MAX_LINES_TO_PRINT)))
except OSError:
print("Opening file %s failed." % fn)
traceback.print_exc()

if success == TestStatus.PASSED:
self.log.info("Tests successful")
sys.exit(TEST_EXIT_PASSED)
exit_code = TEST_EXIT_PASSED
elif success == TestStatus.SKIPPED:
self.log.info("Test skipped")
sys.exit(TEST_EXIT_SKIPPED)
exit_code = TEST_EXIT_SKIPPED
else:
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
logging.shutdown()
sys.exit(TEST_EXIT_FAILED)
self.log.error("Hint: Call {} '{}' to consolidate all logs".format(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
exit_code = TEST_EXIT_FAILED
logging.shutdown()
sys.exit(exit_code)

# Methods to override in subclass test scripts.
def set_test_params(self):
Expand Down
21 changes: 16 additions & 5 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""

import argparse
from collections import deque
import configparser
import datetime
import os
Expand Down Expand Up @@ -361,7 +362,7 @@ def run_tests(*, test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_c
max_len_name = len(max(test_list, key=len))

for _ in range(len(test_list)):
test_result, stdout, stderr = job_queue.get_next()
test_result, testdir, stdout, stderr = job_queue.get_next()
test_results.append(test_result)

if test_result.status == "Passed":
Expand All @@ -372,6 +373,14 @@ def run_tests(*, test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_c
print("\n%s%s%s failed, Duration: %s s\n" % (BOLD[1], test_result.name, BOLD[0], test_result.time))
print(BOLD[1] + 'stdout:\n' + BOLD[0] + stdout + '\n')
print(BOLD[1] + 'stderr:\n' + BOLD[0] + stderr + '\n')
if os.getenv("PYTHON_DEBUG", "") and os.path.isdir(testdir):
# Print the logs on travis, so they are preserved when the vm is disposed
print('{}Combine the logs and print the last {} lines ...{}'.format(BOLD[1], 4000, BOLD[0]))
print('\n============')
print('{}Combined log for {}:{}'.format(BOLD[1], testdir, BOLD[0]))
print('============\n')
combined_logs, _ = subprocess.Popen([os.path.join(tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate()
print("\n".join(deque(combined_logs.splitlines(), 4000)))

if failfast:
logging.debug("Early exiting after test failure")
Expand Down Expand Up @@ -445,13 +454,15 @@ def get_next(self):
log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16)
log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16)
test_argv = t.split()
tmpdir = ["--tmpdir=%s/%s_%s" % (self.tmpdir, re.sub(".py$", "", test_argv[0]), portseed)]
testdir = "{}/{}_{}".format(self.tmpdir, re.sub(".py$", "", test_argv[0]), portseed)
tmpdir_arg = ["--tmpdir={}".format(testdir)]
self.jobs.append((t,
time.time(),
subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir,
subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
universal_newlines=True,
stdout=log_stdout,
stderr=log_stderr),
testdir,
log_stdout,
log_stderr))
if not self.jobs:
Expand All @@ -460,7 +471,7 @@ def get_next(self):
# Return first proc that finishes
time.sleep(.5)
for j in self.jobs:
(name, time0, proc, log_out, log_err) = j
(name, time0, proc, testdir, log_out, log_err) = j
if int(time.time() - time0) > self.timeout_duration:
# In travis, timeout individual tests after 20 minutes (to stop tests hanging and not
# providing useful output.
Expand All @@ -478,7 +489,7 @@ def get_next(self):
self.num_running -= 1
self.jobs.remove(j)

return TestResult(name, status, int(time.time() - time0)), stdout, stderr
return TestResult(name, status, int(time.time() - time0)), testdir, stdout, stderr
print('.', end='', flush=True)

def kill_and_join(self):
Expand Down

0 comments on commit 2a4d173

Please sign in to comment.