From 2ea7c8837bae482bd4a3cc37025baa7e2f456a54 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 6 Aug 2015 12:03:57 -0400 Subject: [PATCH] Handle incomplete subunit streams If a subunit stream is aborted in the middle (like in the case of a segfault) this causes subunit-trace to emit a stacktrace. This commit attempts to handle this edge case gracefully. Related-Bug: #1482230 Change-Id: I1a8a0a8e2ab65e637c6a5212e324670b7d95d28d --- os_testr/subunit_trace.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/os_testr/subunit_trace.py b/os_testr/subunit_trace.py index 7c00825..967c53f 100755 --- a/os_testr/subunit_trace.py +++ b/os_testr/subunit_trace.py @@ -239,8 +239,13 @@ def run_time(): def worker_stats(worker): tests = RESULTS[worker] num_tests = len(tests) - delta = tests[-1]['timestamps'][1] - tests[0]['timestamps'][0] - return num_tests, delta + stop_time = tests[-1]['timestamps'][1] + start_time = tests[0]['timestamps'][0] + if not start_time or not stop_time: + delta = 'N/A' + else: + delta = stop_time - start_time + return num_tests, str(delta) def print_summary(stream, elapsed_time): @@ -266,8 +271,11 @@ def print_summary(stream, elapsed_time): "Race in testr accounting.\n" % w) else: num, time = worker_stats(w) - stream.write(" - Worker %s (%s tests) => %ss\n" % - (w, num, time)) + out_str = " - Worker %s (%s tests) => %s" % (w, num, time) + if time.isdigit(): + out_str += 's' + out_str += '\n' + stream.write(out_str) def parse_args():