Skip to content

Commit dba94ea

Browse files
committed
[tests] [travis-ci] Move Travis functional test log post processing to test_runner
1 parent bba1c54 commit dba94ea

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Base class for RPC testing."""
66

7-
from collections import deque
87
from enum import Enum
98
import logging
109
import optparse
@@ -149,21 +148,6 @@ def main(self):
149148
shutil.rmtree(self.options.tmpdir)
150149
else:
151150
self.log.warning("Not cleaning up dir %s" % self.options.tmpdir)
152-
if os.getenv("PYTHON_DEBUG", ""):
153-
# Dump the end of the debug logs, to aid in debugging rare
154-
# travis failures.
155-
import glob
156-
filenames = [self.options.tmpdir + "/test_framework.log"]
157-
filenames += glob.glob(self.options.tmpdir + "/node*/regtest/debug.log")
158-
MAX_LINES_TO_PRINT = 1000
159-
for fn in filenames:
160-
try:
161-
with open(fn, 'r') as f:
162-
print("From", fn, ":")
163-
print("".join(deque(f, MAX_LINES_TO_PRINT)))
164-
except OSError:
165-
print("Opening file %s failed." % fn)
166-
traceback.print_exc()
167151

168152
if success == TestStatus.PASSED:
169153
self.log.info("Tests successful")

test/functional/test_runner.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
import argparse
18+
from collections import deque
1819
import configparser
1920
import datetime
2021
import os
@@ -314,7 +315,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
314315
max_len_name = len(max(test_list, key=len))
315316

316317
for _ in range(len(test_list)):
317-
test_result, stdout, stderr = job_queue.get_next()
318+
test_result, testdir, stdout, stderr = job_queue.get_next()
318319
test_results.append(test_result)
319320

320321
if test_result.status == "Passed":
@@ -325,6 +326,14 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
325326
print("\n%s%s%s failed, Duration: %s s\n" % (BOLD[1], test_result.name, BOLD[0], test_result.time))
326327
print(BOLD[1] + 'stdout:\n' + BOLD[0] + stdout + '\n')
327328
print(BOLD[1] + 'stderr:\n' + BOLD[0] + stderr + '\n')
329+
if os.getenv("PYTHON_DEBUG", "") and os.path.isdir(testdir):
330+
# Print the logs on travis, so they are preserved when the vm is disposed
331+
print('{}Combine the logs and print the last {} lines ...{}'.format(BOLD[1], 4000, BOLD[0]))
332+
print('\n============')
333+
print('{}Combined log for {}:{}'.format(BOLD[1], testdir, BOLD[0]))
334+
print('============\n')
335+
combined_logs, _ = subprocess.Popen([os.path.join(tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate()
336+
print("\n".join(deque(combined_logs.splitlines(), 4000)))
328337

329338
print_results(test_results, max_len_name, (int(time.time() - time0)))
330339

@@ -389,13 +398,15 @@ def get_next(self):
389398
log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16)
390399
log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16)
391400
test_argv = t.split()
392-
tmpdir = ["--tmpdir=%s/%s_%s" % (self.tmpdir, re.sub(".py$", "", test_argv[0]), portseed)]
401+
testdir = "{}/{}_{}".format(self.tmpdir, re.sub(".py$", "", test_argv[0]), portseed)
402+
tmpdir_arg = ["--tmpdir={}".format(testdir)]
393403
self.jobs.append((t,
394404
time.time(),
395-
subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir,
405+
subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
396406
universal_newlines=True,
397407
stdout=log_stdout,
398408
stderr=log_stderr),
409+
testdir,
399410
log_stdout,
400411
log_stderr))
401412
if not self.jobs:
@@ -404,7 +415,7 @@ def get_next(self):
404415
# Return first proc that finishes
405416
time.sleep(.5)
406417
for j in self.jobs:
407-
(name, time0, proc, log_out, log_err) = j
418+
(name, time0, proc, testdir, log_out, log_err) = j
408419
if os.getenv('TRAVIS') == 'true' and int(time.time() - time0) > 20 * 60:
409420
# In travis, timeout individual tests after 20 minutes (to stop tests hanging and not
410421
# providing useful output.
@@ -422,7 +433,7 @@ def get_next(self):
422433
self.num_running -= 1
423434
self.jobs.remove(j)
424435

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

428439
class TestResult():

0 commit comments

Comments
 (0)