Skip to content

Commit c6080e4

Browse files
authored
Increased FCM batch request limit to 500 (#362)
1 parent 1199712 commit c6080e4

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

firebase_admin/_messaging_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class MulticastMessage(object):
7777
def __init__(self, tokens, data=None, notification=None, android=None, webpush=None, apns=None,
7878
fcm_options=None):
7979
_Validators.check_string_list('MulticastMessage.tokens', tokens)
80-
if len(tokens) > 100:
81-
raise ValueError('MulticastMessage.tokens must not contain more than 100 tokens.')
80+
if len(tokens) > 500:
81+
raise ValueError('MulticastMessage.tokens must not contain more than 500 tokens.')
8282
self.tokens = tokens
8383
self.data = data
8484
self.notification = notification

firebase_admin/messaging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ def send(self, message, dry_run=False):
356356
def send_all(self, messages, dry_run=False):
357357
"""Sends the given messages to FCM via the batch API."""
358358
if not isinstance(messages, list):
359-
raise ValueError('Messages must be an list of messaging.Message instances.')
360-
if len(messages) > 100:
361-
raise ValueError('send_all messages must not contain more than 100 messages.')
359+
raise ValueError('messages must be a list of messaging.Message instances.')
360+
if len(messages) > 500:
361+
raise ValueError('messages must not contain more than 500 elements.')
362362

363363
responses = []
364364

integration/test_messaging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ def test_send_all():
101101
assert isinstance(response.exception, exceptions.InvalidArgumentError)
102102
assert response.message_id is None
103103

104-
def test_send_one_hundred():
104+
def test_send_all_500():
105105
messages = []
106-
for msg_number in range(100):
106+
for msg_number in range(500):
107107
topic = 'foo-bar-{0}'.format(msg_number % 10)
108108
messages.append(messaging.Message(topic=topic))
109109

110110
batch_response = messaging.send_all(messages, dry_run=True)
111111

112-
assert batch_response.success_count == 100
112+
assert batch_response.success_count == 500
113113
assert batch_response.failure_count == 0
114-
assert len(batch_response.responses) == 100
114+
assert len(batch_response.responses) == 500
115115
for response in batch_response.responses:
116116
assert response.success is True
117117
assert response.exception is None

tests/test_messaging.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ def test_invalid_tokens_type(self, tokens):
102102
expected = 'MulticastMessage.tokens must be a list of strings.'
103103
assert str(excinfo.value) == expected
104104

105-
def test_tokens_over_one_hundred(self):
105+
def test_tokens_over_500(self):
106106
with pytest.raises(ValueError) as excinfo:
107-
messaging.MulticastMessage(tokens=['token' for _ in range(0, 101)])
108-
expected = 'MulticastMessage.tokens must not contain more than 100 tokens.'
107+
messaging.MulticastMessage(tokens=['token' for _ in range(0, 501)])
108+
expected = 'MulticastMessage.tokens must not contain more than 500 tokens.'
109109
assert str(excinfo.value) == expected
110110

111111
def test_tokens_type(self):
112-
messaging.MulticastMessage(tokens=['token'])
113-
messaging.MulticastMessage(tokens=['token' for _ in range(0, 100)])
112+
message = messaging.MulticastMessage(tokens=['token'])
113+
assert len(message.tokens) == 1
114+
115+
message = messaging.MulticastMessage(tokens=['token' for _ in range(0, 500)])
116+
assert len(message.tokens) == 500
114117

115118

116119
class TestMessageEncoder(object):
@@ -1598,14 +1601,14 @@ def test_invalid_send_all(self, msg):
15981601
expected = 'Message must be an instance of messaging.Message class.'
15991602
assert str(excinfo.value) == expected
16001603
else:
1601-
expected = 'Messages must be an list of messaging.Message instances.'
1604+
expected = 'messages must be a list of messaging.Message instances.'
16021605
assert str(excinfo.value) == expected
16031606

1604-
def test_invalid_over_one_hundred(self):
1607+
def test_invalid_over_500(self):
16051608
msg = messaging.Message(topic='foo')
16061609
with pytest.raises(ValueError) as excinfo:
1607-
messaging.send_all([msg for _ in range(0, 101)])
1608-
expected = 'send_all messages must not contain more than 100 messages.'
1610+
messaging.send_all([msg for _ in range(0, 501)])
1611+
expected = 'messages must not contain more than 500 elements.'
16091612
assert str(excinfo.value) == expected
16101613

16111614
def test_send_all(self):

0 commit comments

Comments
 (0)