Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt to acknowledge 0 messages #2879

Merged
merged 2 commits into from
Dec 16, 2016
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