Skip to content

Commit a514703

Browse files
authored
Merge pull request #2879 from quom/master
Do not attempt to acknowledge 0 messages
2 parents e26b437 + 33cee11 commit a514703

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pubsub/google/cloud/pubsub/subscription.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,5 @@ def __enter__(self):
509509
return self
510510

511511
def __exit__(self, exc_type, exc_val, exc_tb):
512-
self._subscription.acknowledge(list(self), self._client)
512+
if self:
513+
self._subscription.acknowledge(list(self), self._client)

pubsub/unit_tests/test_subscription.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import unittest
1616

17+
import mock
18+
1719

1820
class TestSubscription(unittest.TestCase):
1921
PROJECT = 'PROJECT'
@@ -745,6 +747,16 @@ def test___exit___(self):
745747
[ACK_ID1, ACK_ID2])
746748
self.assertIs(subscription._ack_client, CLIENT)
747749

750+
def test_empty_ack_no_acknowledge(self):
751+
subscription = mock.Mock(_FauxSubscription)
752+
subscription.pull = lambda *args: []
753+
754+
auto_ack = self._make_one(subscription)
755+
with auto_ack:
756+
pass
757+
758+
subscription.acknowledge.assert_not_called()
759+
748760

749761
class _FauxIAMPolicy(object):
750762

0 commit comments

Comments
 (0)