diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | testrepository/repository/file.py | 2 | ||||
-rw-r--r-- | testrepository/repository/memory.py | 2 | ||||
-rw-r--r-- | testrepository/tests/test_repository.py | 32 |
4 files changed, 34 insertions, 7 deletions
@@ -18,6 +18,11 @@ CHANGES * Test filtering was failing under python3 and would only apply the filters to the first test listed by discover. (Clark Boylan, #1317607) +* 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. (Robert Collins, #1322763) + * Version 0.0.18 of subunit is now a hard dependency - the v2 protocol solves key issues in concurrency and stream handling. Users that cannot use subunit v2 can run an older testrepository, or contact upstream to work through diff --git a/testrepository/repository/file.py b/testrepository/repository/file.py index 5de131d..1ab3a87 100644 --- a/testrepository/repository/file.py +++ b/testrepository/repository/file.py @@ -240,7 +240,7 @@ class _SafeInserter(object): def _handle_test(self, test_dict): start, stop = test_dict['timestamps'] - if None in (start, stop): + if test_dict['status'] == 'exists' or None in (start, stop): return self._times[test_dict['id']] = str(timedelta_to_seconds(stop - start)) diff --git a/testrepository/repository/memory.py b/testrepository/repository/memory.py index 647a81b..8073280 100644 --- a/testrepository/repository/memory.py +++ b/testrepository/repository/memory.py @@ -151,7 +151,7 @@ class _Inserter(AbstractTestRun): def _handle_test(self, test_dict): self._tests.append(test_dict) start, stop = test_dict['timestamps'] - if None in (start, stop): + if test_dict['status'] == 'exists' or None in (start, stop): return duration_delta = stop - start duration_seconds = ((duration_delta.microseconds + diff --git a/testrepository/tests/test_repository.py b/testrepository/tests/test_repository.py index 1bc9162..e2e5e05 100644 --- a/testrepository/tests/test_repository.py +++ b/testrepository/tests/test_repository.py @@ -119,12 +119,18 @@ def make_test(id, should_pass): return clone_test_with_new_id(case, id) -def run_timed(id, duration, result): - """Make and run a test taking duration seconds.""" +def run_timed(id, duration, result, enumeration=False): + """Make and run a test taking duration seconds. + + :param enumeration: If True, don't run, just enumerate. + """ start = datetime.now(tz=iso8601.Utc()) - result.status(test_id=id, test_status='inprogress', timestamp=start) - result.status(test_id=id, test_status='success', - timestamp=start + timedelta(seconds=duration)) + if enumeration: + result.status(test_id=id, test_status='exists', timestamp=start) + else: + result.status(test_id=id, test_status='inprogress', timestamp=start) + result.status(test_id=id, test_status='success', + timestamp=start + timedelta(seconds=duration)) class TestRepositoryErrors(ResourcedTestCase): @@ -515,6 +521,22 @@ class TestRepositoryContract(ResourcedTestCase): self.assertEqual({test_name: 0.1}, repo.get_test_times([test_name])['known']) + def test_inserted_exists_no_impact_on_test_times(self): + repo = self.repo_impl.initialise(self.sample_url) + result = repo.get_inserter() + legacy_result = testtools.ExtendedToStreamDecorator(result) + legacy_result.startTestRun() + test_name = 'testrepository.tests.test_repository.Case.method' + run_timed(test_name, 0.1, legacy_result) + legacy_result.stopTestRun() + result = repo.get_inserter() + result.startTestRun() + test_name = 'testrepository.tests.test_repository.Case.method' + run_timed(test_name, 0.2, result, True) + result.stopTestRun() + self.assertEqual({test_name: 0.1}, + repo.get_test_times([test_name])['known']) + def test_get_test_ids(self): repo = self.repo_impl.initialise(self.sample_url) inserter = repo.get_inserter() |