diff --git a/autopush/tests/test_web_base.py b/autopush/tests/test_web_base.py index 7f406df4..1e08ee3e 100644 --- a/autopush/tests/test_web_base.py +++ b/autopush/tests/test_web_base.py @@ -1,7 +1,6 @@ import sys import uuid -from boto.exception import BotoServerError from botocore.exceptions import ClientError from mock import Mock, patch from twisted.internet.defer import Deferred @@ -202,7 +201,7 @@ def test_connection_err(self): self.base._response_err(fail) assert not self.status_mock.called - def test_overload_err(self): + def test_boto_err_overload(self): try: raise ClientError( {'Error': { @@ -211,10 +210,10 @@ def test_overload_err(self): ) except ClientError: fail = Failure() - self.base._overload_err(fail) + self.base._boto_err(fail) self.status_mock.assert_called_with(503, reason=None) - def test_client_err(self): + def test_boto_err_random(self): try: raise ClientError( {'Error': { @@ -223,14 +222,6 @@ def test_client_err(self): ) except ClientError: fail = Failure() - self.base._overload_err(fail) - self.status_mock.assert_called_with(500, reason=None) - - def test_boto_err(self): - try: - raise BotoServerError(503, "derp") - except BotoServerError: - fail = Failure() self.base._boto_err(fail) self.status_mock.assert_called_with(503, reason=None) diff --git a/autopush/tests/test_websocket.py b/autopush/tests/test_websocket.py index b08a2918..7a9d571e 100644 --- a/autopush/tests/test_websocket.py +++ b/autopush/tests/test_websocket.py @@ -1104,6 +1104,31 @@ def raise_condition(*args, **kwargs): assert msg["messageType"] == "error" assert msg["reason"] == "overloaded" + @inlineCallbacks + def test_register_ise(self): + self._connect() + chid = str(uuid.uuid4()) + self.proto.ps.uaid = uuid.uuid4().hex + msg_mock = Mock(spec=db.Message) + msg_mock.register_channel = register = Mock() + self.proto.ps.db.message_table = Mock(return_value=msg_mock) + + def raise_condition(*args, **kwargs): + raise ClientError( + {'Error': {'Code': 'InternalServerError'}}, + 'mock_update_item' + ) + + register.side_effect = raise_condition + + yield self.proto.process_register(dict(channelID=chid)) + assert msg_mock.register_channel.called + assert self.send_mock.called + args, _ = self.send_mock.call_args + msg = json.loads(args[0]) + assert msg["messageType"] == "error" + assert msg["reason"] == "overloaded" + def test_check_kill_self(self): self._connect() node_id = "http://localhost" diff --git a/autopush/web/base.py b/autopush/web/base.py index 7422f23d..8e4a76ae 100644 --- a/autopush/web/base.py +++ b/autopush/web/base.py @@ -2,7 +2,6 @@ import time from functools import wraps -from boto.exception import BotoServerError from botocore.exceptions import ClientError from marshmallow.schema import UnmarshalResult # noqa from typing import ( # noqa @@ -92,7 +91,8 @@ def wrapper(request_handler, *args, **kwargs): d.addBoth(self._track_validation_timing, request_handler, start_time) d.addCallback(self._call_func, func, request_handler) - d.addErrback(request_handler._overload_err) + # Errbacks for _validate_request: handler functions should + # explicitly manage their own Errbacks d.addErrback(request_handler._boto_err) d.addErrback(request_handler._validation_err) d.addErrback(request_handler._response_err) @@ -248,8 +248,8 @@ def _response_err(self, fail): self._write_response(500, 999, message="An unexpected server error" " occurred.") - def _overload_err(self, fail): - """errBack for throughput provisioned exceptions""" + def _boto_err(self, fail): + """errBack for boto exceptions (ClientError)""" fail.trap(ClientError) if (fail.value.response['Error']['Code'] == "ProvisionedThroughputExceededException"): @@ -259,18 +259,9 @@ def _overload_err(self, fail): message="Please slow message send rate") return self.log.debug(format="Unhandled Client Error: {}".format( - json.dumps(fail.value.response)), status_code=500, + json.dumps(fail.value.response)), status_code=503, errno=202, client_info=self._client_info) - self._write_response(500, 999, message="Unexpected Error") - - def _boto_err(self, fail): - """errBack for random boto exceptions""" - fail.trap(BotoServerError) - self.log.debug(format="BOTO Error: %s" % str(fail.value), - status_code=503, errno=202, - client_info=self._client_info) - self._write_response(503, errno=202, - message="Communication error, please retry") + self._write_response(503, 202, message="Unexpected Error") def _router_response(self, response, router_type, vapid): for name, val in response.headers.items(): @@ -342,7 +333,6 @@ def _write_validation_err(self, errors): def _db_error_handling(self, d): """Tack on the common error handling for a dynamodb request and uncaught exceptions""" - d.addErrback(self._overload_err) d.addErrback(self._boto_err) d.addErrback(self._response_err) return d diff --git a/autopush/websocket.py b/autopush/websocket.py index ef7f63cd..5ab845c7 100644 --- a/autopush/websocket.py +++ b/autopush/websocket.py @@ -673,9 +673,6 @@ def error_overload(self, failure, message_type, disconnect=True): self.error_finish_overload, message_type) d.addErrback(self.trap_cancel) else: - if (failure.value.response["Error"]["Code"] != - "ProvisionedThroughputExceededException"): - return failure # pragma nocover send = {"messageType": "error", "reason": "overloaded", "status": 503} self.sendJSON(send)