Skip to content

Commit 1ec5bd0

Browse files
committed
Fix 0 timestamps for enumerated but not run tests.
Tests that are enumerated but not executed will no longer reset the test timing data. Enumeration was incorrectly recording a 0 timestamp for enumerated tests. This leads to poor scheduling after an interrupted test run.
1 parent 056c994 commit 1ec5bd0

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ CHANGES
1818
* Test filtering was failing under python3 and would only apply the
1919
filters to the first test listed by discover. (Clark Boylan, #1317607)
2020

21+
* Tests that are enumerated but not executed will no longer reset the test
22+
timing data. Enumeration was incorrectly recording a 0 timestamp for
23+
enumerated tests. This leads to poor scheduling after an interrupted test
24+
run. (Robert Collins)
25+
2126
* Version 0.0.18 of subunit is now a hard dependency - the v2 protocol solves
2227
key issues in concurrency and stream handling. Users that cannot use subunit
2328
v2 can run an older testrepository, or contact upstream to work through

testrepository/repository/file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def __init__(self, repository, partial=False):
240240

241241
def _handle_test(self, test_dict):
242242
start, stop = test_dict['timestamps']
243-
if None in (start, stop):
243+
if test_dict['status'] == 'exists' or None in (start, stop):
244244
return
245245
self._times[test_dict['id']] = str(timedelta_to_seconds(stop - start))
246246

testrepository/repository/memory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def startTestRun(self):
151151
def _handle_test(self, test_dict):
152152
self._tests.append(test_dict)
153153
start, stop = test_dict['timestamps']
154-
if None in (start, stop):
154+
if test_dict['status'] == 'exists' or None in (start, stop):
155155
return
156156
duration_delta = stop - start
157157
duration_seconds = ((duration_delta.microseconds +

testrepository/tests/test_repository.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,18 @@ def make_test(id, should_pass):
119119
return clone_test_with_new_id(case, id)
120120

121121

122-
def run_timed(id, duration, result):
123-
"""Make and run a test taking duration seconds."""
122+
def run_timed(id, duration, result, enumeration=False):
123+
"""Make and run a test taking duration seconds.
124+
125+
:param enumeration: If True, don't run, just enumerate.
126+
"""
124127
start = datetime.now(tz=iso8601.Utc())
125-
result.status(test_id=id, test_status='inprogress', timestamp=start)
126-
result.status(test_id=id, test_status='success',
127-
timestamp=start + timedelta(seconds=duration))
128+
if enumeration:
129+
result.status(test_id=id, test_status='exists', timestamp=start)
130+
else:
131+
result.status(test_id=id, test_status='inprogress', timestamp=start)
132+
result.status(test_id=id, test_status='success',
133+
timestamp=start + timedelta(seconds=duration))
128134

129135

130136
class TestRepositoryErrors(ResourcedTestCase):
@@ -515,6 +521,22 @@ def test_inserted_test_times_known(self):
515521
self.assertEqual({test_name: 0.1},
516522
repo.get_test_times([test_name])['known'])
517523

524+
def test_inserted_exists_no_impact_on_test_times(self):
525+
repo = self.repo_impl.initialise(self.sample_url)
526+
result = repo.get_inserter()
527+
legacy_result = testtools.ExtendedToStreamDecorator(result)
528+
legacy_result.startTestRun()
529+
test_name = 'testrepository.tests.test_repository.Case.method'
530+
run_timed(test_name, 0.1, legacy_result)
531+
legacy_result.stopTestRun()
532+
result = repo.get_inserter()
533+
result.startTestRun()
534+
test_name = 'testrepository.tests.test_repository.Case.method'
535+
run_timed(test_name, 0.2, result, True)
536+
result.stopTestRun()
537+
self.assertEqual({test_name: 0.1},
538+
repo.get_test_times([test_name])['known'])
539+
518540
def test_get_test_ids(self):
519541
repo = self.repo_impl.initialise(self.sample_url)
520542
inserter = repo.get_inserter()

0 commit comments

Comments
 (0)