Skip to content

Commit

Permalink
fix: ensure exception is available when BackgroundConsumer open strea…
Browse files Browse the repository at this point in the history
…m fails
  • Loading branch information
parthea committed Mar 14, 2022
1 parent c89f55d commit 7f05e51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion google/api_core/bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ def open(self):
request_generator = _RequestQueueGenerator(
self._request_queue, initial_request=self._initial_request
)
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata)
try:
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata)
except exceptions.GoogleAPICallError as exc:
self._on_call_done(exc)
raise

request_generator.call = call

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,20 @@ def test_wake_on_error(self):
while consumer.is_active:
pass

def test_rpc_callback_fires_when_consumer_start_fails(self):
expected_exception = exceptions.InvalidArgument("test")
callback = mock.Mock(spec=["__call__"])
rpc, _ = make_rpc()
bidi_rpc = bidi.BidiRpc(rpc)
bidi_rpc.add_done_callback(callback)
bidi_rpc._start_rpc.side_effect = expected_exception

consumer = bidi.BackgroundConsumer(bidi_rpc, on_response=lambda: None)

consumer.start()

assert callback.call_args.args[0] == expected_exception

def test_consumer_expected_error(self, caplog):
caplog.set_level(logging.DEBUG)

Expand Down

0 comments on commit 7f05e51

Please sign in to comment.