Skip to content
Permalink
Browse files
fix: shutdown error on streaming pull callback error (#40)
* fix: shutdown error on streaming pull callback error

* fix incorrect comment
  • Loading branch information
plamut committed Feb 28, 2020
1 parent 380cb38 commit 552539e7beb30833c39dd29bfcb0183a07895f97
Showing with 17 additions and 0 deletions.
  1. +5 −0 google/cloud/pubsub_v1/subscriber/futures.py
  2. +12 −0 tests/unit/pubsub_v1/subscriber/test_futures_subscriber.py
@@ -33,6 +33,11 @@ def __init__(self, manager):
self._cancelled = False

def _on_close_callback(self, manager, result):
if self.done():
# The future has already been resolved in a different thread,
# nothing to do on the streaming pull manager shutdown.
return

if result is None:
self.set_result(True)
else:
@@ -57,6 +57,18 @@ def test__on_close_callback_failure(self):

assert not future.running()

def test__on_close_callback_future_already_done(self):
future = self.make_future()

future.set_result("foo")
assert future.done()

# invoking on close callback should not result in an error
future._on_close_callback(mock.sentinel.manager, "bar")

result = future.result()
assert result == "foo" # on close callback was a no-op

def test_cancel(self):
future = self.make_future()

0 comments on commit 552539e

Please sign in to comment.