Skip to content

Commit

Permalink
Treat ESME_RMSGQFUL responses the same as EMSE_RTHROTTLED responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Oct 27, 2013
1 parent 782f323 commit e7455a4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
43 changes: 42 additions & 1 deletion vumi/transports/smpp/tests/test_smpp.py
Expand Up @@ -222,7 +222,7 @@ def test_delivery_report_for_unknown_message(self):
"discarded.",))

@inlineCallbacks
def test_throttled_submit(self):
def test_throttled_submit_ESME_RTHROTTLED(self):
clock = Clock()
self.transport.callLater = clock.callLater

Expand Down Expand Up @@ -262,6 +262,47 @@ def assert_throttled_status(throttled, messages, acks):
False, ["Heimlich", "Heimlich", "Other"],
[('447', '3rd_party_5'), ('448', '3rd_party_6')])

@inlineCallbacks
def test_throttled_submit_ESME_RMSGQFUL(self):
clock = Clock()
self.transport.callLater = clock.callLater

def assert_throttled_status(throttled, messages, acks):
self.assertEqual(self.transport.throttled, throttled)
self.assert_sent_contents(messages)
self.assertEqual(acks, [
(m['user_message_id'], m['sent_message_id'])
for m in self.get_dispatched_events()])
self.assertEqual([], self.get_dispatched_failures())

assert_throttled_status(False, [], [])

message = self.msg_helper.make_outbound("Heimlich", message_id="447")
response = SubmitSMResp(1, "3rd_party_id_4",
command_status="ESME_RMSGQFUL")
yield self.dispatch(message)
yield self.esme.handle_data(response.get_bin())

assert_throttled_status(True, ["Heimlich"], [])
# Still waiting to resend
clock.advance(0.05)
yield self.transport.redis.exists('wait for redis')
assert_throttled_status(True, ["Heimlich"], [])
message2 = self.msg_helper.make_outbound("Other", message_id="448")
yield self.dispatch(message2)
assert_throttled_status(True, ["Heimlich"], [])
# Resent
clock.advance(0.05)
yield self.transport.redis.exists('wait for redis')
assert_throttled_status(True, ["Heimlich", "Heimlich"], [])
# And acknowledged by the other side
yield self.esme.handle_data(SubmitSMResp(2, "3rd_party_5").get_bin())
yield self._amqp.kick_delivery()
yield self.esme.handle_data(SubmitSMResp(3, "3rd_party_6").get_bin())
assert_throttled_status(
False, ["Heimlich", "Heimlich", "Other"],
[('447', '3rd_party_5'), ('448', '3rd_party_6')])

@inlineCallbacks
def test_reconnect(self):
connector = self.transport.connectors[self.transport.transport_name]
Expand Down
4 changes: 2 additions & 2 deletions vumi/transports/smpp/transport.py
Expand Up @@ -117,7 +117,7 @@ class SmppTransportConfig(Transport.CONFIG_CLASS):
"work.", default='', static=True)
throttle_delay = ConfigFloat(
"Delay (in seconds) before retrying a message after receiving "
"`ESME_RTHROTTLED`.", default=0.1, static=True)
"`ESME_RTHROTTLED` or `ESME_RMSGQFUL`.", default=0.1, static=True)
COUNTRY_CODE = ConfigText(
"Used to translate a leading zero in a destination MSISDN into a "
"country code. Default ''", default="", static=True)
Expand Down Expand Up @@ -334,7 +334,7 @@ def submit_sm_resp(self, *args, **kwargs):
# The sms was submitted ok
yield self.submit_sm_success(sent_sms_id, transport_msg_id)
yield self._stop_throttling()
elif status == 'ESME_RTHROTTLED':
elif status in ('ESME_RTHROTTLED', 'ESME_RMSGQFUL'):
yield self._start_throttling()
yield self.submit_sm_throttled(sent_sms_id)
else:
Expand Down

0 comments on commit e7455a4

Please sign in to comment.