Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions gtest_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def run(self, timeout_per_test):
try:
self.exit_code = sigint_handler.wait(task, timeout_per_test)
except sigint_handler.ProcessWasInterrupted:
self.runtime_ms = int(1000 * (time.time() - begin))
thread.exit()
self.runtime_ms = int(1000 * (time.time() - begin))
self.last_execution_time = None if self.exit_code else self.runtime_ms
Expand Down Expand Up @@ -359,9 +360,13 @@ def print_tests(self, message, tasks, print_try_number, print_test_command):
self.out.permanent_line("%s (%s/%s):" %
(message, len(tasks), self.total_tasks))
for task in sorted(tasks):
runtime_ms = 'Interrupted'
if task.runtime_ms is not None:
if message == 'INTERRUPTED TESTS':
runtime_ms = ('Interrupted: %d ms' % task.runtime_ms
if task.runtime_ms is not None else 'Interrupted')
elif task.runtime_ms is not None:
runtime_ms = '%d ms' % task.runtime_ms
else:
runtime_ms = 'Interrupted'
if print_test_command:
try:
cmd_str = " ".join(task.test_command)
Expand Down
34 changes: 34 additions & 0 deletions gtest_parallel_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ def run_test(_):

self.assertTrue(os.path.isfile(task.log_file))
self.assertIsNone(task.exit_code)
self.assertIsNotNone(task.runtime_ms)
self.assertGreaterEqual(task.runtime_ms, 0)

self._execute_run_test(run_test, True)

Expand Down Expand Up @@ -504,6 +506,38 @@ def run_test(logger):

self._execute_test(run_test, False)

def test_print_interrupted_tests_shows_runtime(self):
class StdoutCapture(object):
def __init__(self):
self.lines = []

def isatty(self):
return False

def write(self, msg):
self.lines.append(msg)

def flush(self):
pass

stdout = StdoutCapture()
with guard_patch_module('sys.stdout', stdout):
logger = gtest_parallel.FilterFormat(None)
logger.log_tasks(1)
interrupted = [
TaskMock(
('fake/binary', 'FakeTest'), 0, {
'runtime_ms': [1078216],
'exit_code': [None],
'last_execution_time': [None],
})
]
logger.print_tests('INTERRUPTED TESTS', interrupted,
print_try_number=False, print_test_command=False)

output = ''.join(stdout.lines)
self.assertIn('Interrupted: 1078216 ms: fake/binary FakeTest', output)


class TestFindTests(unittest.TestCase):
ONE_DISABLED_ONE_ENABLED_TEST = {
Expand Down