Skip to content

Commit 0a968fb

Browse files
committed
Add additional test assertions about sent ACK IDs
The tests should also check that each message is (MOD)ACK-ed exactly once.
1 parent 86f1d7f commit 0a968fb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pubsub/tests/unit/pubsub_v1/subscriber/test_dispatcher.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import collections
1516
import threading
1617

1718
from google.cloud.pubsub_v1 import types
@@ -112,14 +113,15 @@ def test_ack_splitting_large_payload():
112113
assert len(calls) == 3
113114

114115
all_ack_ids = {item.ack_id for item in items}
115-
sent_ack_ids = set()
116+
sent_ack_ids = collections.Counter()
116117

117118
for call in calls:
118119
message = call.args[0]
119120
assert message.ByteSize() <= 524288 # server-side limit (2**19)
120121
sent_ack_ids.update(message.ack_ids)
121122

122-
assert sent_ack_ids == all_ack_ids # all messages should have been ACK-ed
123+
assert set(sent_ack_ids) == all_ack_ids # all messages should have been ACK-ed
124+
assert sent_ack_ids.most_common(1)[0][1] == 1 # each message ACK-ed exactly once
123125

124126

125127
def test_lease():
@@ -197,14 +199,15 @@ def test_modify_ack_deadline_splitting_large_payload():
197199
assert len(calls) == 3
198200

199201
all_ack_ids = {item.ack_id for item in items}
200-
sent_ack_ids = set()
202+
sent_ack_ids = collections.Counter()
201203

202204
for call in calls:
203205
message = call.args[0]
204206
assert message.ByteSize() <= 524288 # server-side limit (2**19)
205207
sent_ack_ids.update(message.modify_deadline_ack_ids)
206208

207-
assert sent_ack_ids == all_ack_ids # all messages should have been ACK-ed
209+
assert set(sent_ack_ids) == all_ack_ids # all messages should have been ACK-ed
210+
assert sent_ack_ids.most_common(1)[0][1] == 1 # each message ACK-ed exactly once
208211

209212

210213
@mock.patch("threading.Thread", autospec=True)

0 commit comments

Comments
 (0)