mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Partial Merge #11789
This commit is contained in:
parent
f12c592b1f
commit
219ff3901f
@ -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
|
||||
@ -174,32 +174,19 @@ class BitcoinTestFramework():
|
||||
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):
|
||||
|
@ -15,6 +15,7 @@ For a description of arguments recognized by test scripts, see
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from collections import deque
|
||||
import configparser
|
||||
import datetime
|
||||
import os
|
||||
@ -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":
|
||||
@ -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")
|
||||
@ -445,13 +454,15 @@ class TestHandler:
|
||||
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:
|
||||
@ -460,7 +471,7 @@ class TestHandler:
|
||||
# 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.
|
||||
@ -478,7 +489,7 @@ class TestHandler:
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user