Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pubsub/google/cloud/pubsub/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,5 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self._subscription.acknowledge(list(self), self._client)
if self:
self._subscription.acknowledge(list(self), self._client)
12 changes: 12 additions & 0 deletions pubsub/unit_tests/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import unittest

import mock


class TestSubscription(unittest.TestCase):
PROJECT = 'PROJECT'
Expand Down Expand Up @@ -745,6 +747,16 @@ def test___exit___(self):
[ACK_ID1, ACK_ID2])
self.assertIs(subscription._ack_client, CLIENT)

def test_empty_ack_no_acknowledge(self):
subscription = mock.Mock(_FauxSubscription)
subscription.pull = lambda *args: []

auto_ack = self._make_one(subscription)
with auto_ack:
pass

subscription.acknowledge.assert_not_called()


class _FauxIAMPolicy(object):

Expand Down