Skip to content
Draft
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
15 changes: 11 additions & 4 deletions sdks/python/apache_beam/ml/inference/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ def create_client(self):
return FakeModel()

def request(self, batch, model, inference_args=None) -> Iterable[int]:
raise Exception
raise RuntimeError('fake remote inference request failed')

def batch_elements_kwargs(self):
return {
Expand Down Expand Up @@ -2475,22 +2475,29 @@ def test_normal_model_execution(self):
actual = pcoll | base.RunInference(FakeRemoteModelHandler())
assert_that(actual, equal_to(expected), label='assert:inferences')

def test_repeated_requests_fail(self):
@unittest.mock.patch.object(base.ReactiveThrottler, 'throttle')
@unittest.mock.patch.object(base.retry.Clock, 'sleep')
def test_repeated_requests_fail(self, sleep, unused_throttle):
test_pipeline = TestPipeline()
with self.assertRaises(Exception):
with self.assertRaisesRegex(RuntimeError,
'fake remote inference request failed'):
_ = (
test_pipeline
| beam.Create([1, 2, 3, 4])
| base.RunInference(FakeAlwaysFailsRemoteModelHandler()))
test_pipeline.run()
self.assertEqual(sleep.call_count, 2)

def test_works_on_retry(self):
@unittest.mock.patch.object(base.ReactiveThrottler, 'throttle')
@unittest.mock.patch.object(base.retry.Clock, 'sleep')
def test_works_on_retry(self, sleep, unused_throttle):
with TestPipeline() as pipeline:
examples = [1, 5, 3, 10]
expected = [example + 1 for example in examples]
pcoll = pipeline | 'start' >> beam.Create(examples)
actual = pcoll | base.RunInference(FakeFailsOnceRemoteModelHandler())
assert_that(actual, equal_to(expected), label='assert:inferences')
sleep.assert_called()

def test_exception_on_load_model_override(self):
with self.assertRaises(Exception):
Expand Down
Loading