Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

bug: don't return 503 for disconnected user #384

Merged
merged 1 commit into from
Mar 4, 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
6 changes: 2 additions & 4 deletions autopush/router/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def route_notification(self, notification, uaid_data):
# - Error (Client gone, node gone/dead): Clear node entry for user
# - Both: Done, return 503
if node_id:
result = None
try:
result = yield self._send_notification(uaid, node_id,
notification)
Expand All @@ -107,10 +108,7 @@ def route_notification(self, notification, uaid_data):
uaid_data).addErrback(self._eat_db_err)
if isinstance(exc, ConnectionRefusedError):
log.err("Could not route message: %s" % repr(exc))
raise RouterException("Node was invalid", status_code=503,
response_body="Retry Request",
log_exception=False, errno=202)
if result.code == 200:
if result and result.code == 200:
self.metrics.increment("router.broadcast.hit")
returnValue(self.delivered_response(notification))

Expand Down
23 changes: 6 additions & 17 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,32 +489,21 @@ def _contains_err(self, string):
return True
return False # pragma: nocover

def test_route_connection_refused_error(self):
def test_route_connection_fail_saved(self):
self.agent_mock.request.side_effect = MockAssist(
[self._raise_connection_refused_error])
router_data = dict(node_id="http://somewhere", uaid=dummy_uaid)
self.router_mock.clear_node.return_value = None
self.router_mock.get_uaid.return_value = {}
log.addObserver(self._mockObserver)
self.storage_mock.save_notification.return_value = True
d = self.router.route_notification(self.notif, router_data)

def verify_retry(fail):
exc = fail.value
ok_(exc, RouterException)
eq_(exc.status_code, 503)
eq_(len(self.router_mock.clear_node.mock_calls), 1)
self.router_mock.clear_node.reset_mock()
self.flushLoggedErrors()

def verify_deliver(fail):
def verify_deliver(reply):
ok_(self._contains_err('ConnectionRefusedError'))
exc = fail.value
ok_(exc, RouterException)
eq_(exc.status_code, 503)
ok_(reply.status_code, 202)
eq_(len(self.router_mock.clear_node.mock_calls), 1)
self.router_mock.clear_node.reset_mock()
d = self.router.route_notification(self.notif, router_data)
d.addBoth(verify_retry)
return d

d.addBoth(verify_deliver)
return d

Expand Down