Skip to content

Commit

Permalink
Add tests that verify finalize_batch is being called when it is expec…
Browse files Browse the repository at this point in the history
…ted and not being called when it is unexpected.
  • Loading branch information
dbernstein committed Sep 11, 2024
1 parent 650814a commit 89ec3d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/manager/core/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def process_batch_and_handle_results(self, batch):
assert 1 == progress.successes
assert 2 == progress.transient_failures
assert 3 == progress.persistent_failures
assert provider.finalize_batch_called

assert (
"Items processed: 6. Successes: 1, transient failures: 2, persistent failures: 3"
Expand Down Expand Up @@ -608,6 +609,9 @@ class MockProvider4(NeverSuccessfulCoverageProvider):
assert [CoverageRecord.PERSISTENT_FAILURE] * 2 == [x.status for x in results]
assert ["i will always fail"] * 2 == [x.operation for x in results]

assert not success_provider.finalize_batch_called
assert not persistent_failure_provider.finalize_batch_called

def test_process_batch(self, db: DatabaseTransactionFixture):
class Mock(BaseCoverageProvider):
SERVICE_NAME = "Some succeed, some fail."
Expand Down Expand Up @@ -1150,6 +1154,8 @@ def test_run_on_specific_identifiers(self, db: DatabaseTransactionFixture):
for i in not_to_be_tested:
assert i not in provider.attempts

assert provider.finalize_batch_called

def test_run_on_specific_identifiers_respects_cutoff_time(
self, db: DatabaseTransactionFixture
):
Expand Down Expand Up @@ -1193,6 +1199,7 @@ def test_run_on_specific_identifiers_respects_cutoff_time(
# reflect the failure.
assert records[0] == record
assert "What did you expect?" == record.exception
assert provider.finalize_batch_called

def test_run_never_successful(self, db: DatabaseTransactionFixture):
"""Verify that NeverSuccessfulCoverageProvider works the
Expand Down
4 changes: 4 additions & 0 deletions tests/mocks/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ class InstrumentedCoverageProvider(MockCoverageProvider, IdentifierCoverageProvi
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.attempts = []
self.finalize_batch_called = False

def process_item(self, item):
self.attempts.append(item)
return item

def finalize_batch(self):
self.finalize_batch_called = True


class InstrumentedWorkCoverageProvider(MockCoverageProvider, WorkCoverageProvider):
"""A WorkCoverageProvider that keeps track of every item it tried
Expand Down

0 comments on commit 89ec3d7

Please sign in to comment.