diff --git a/autopush/tests/test_websocket.py b/autopush/tests/test_websocket.py index 85c81f7c..a63e37b3 100644 --- a/autopush/tests/test_websocket.py +++ b/autopush/tests/test_websocket.py @@ -7,7 +7,8 @@ import twisted.internet.base from autopush.tests.test_db import make_webpush_notification -from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException +from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException, \ + ItemNotFound from boto.exception import JSONResponseError from cyclone.web import Application from mock import Mock, patch @@ -459,7 +460,41 @@ def wait_for_agent_call(): # pragma: nocover reactor.callLater(0.1, wait_for_agent_call) mock_metrics.increment.assert_called_with( - "error.notify_uaid_failure", tags=None) + "client.notify_uaid_failure", tags=None) + d.callback(True) + reactor.callLater(0.1, wait_for_agent_call) + return d + + def test_close_with_delivery_cleanup_and_no_get_uaid_error(self): + self._connect() + self.proto.ps.uaid = uuid.uuid4().hex + self.proto.ap_settings.clients["asdf"] = self.proto + chid = str(uuid.uuid4()) + + # Stick an un-acked direct notification in + self.proto.ps.direct_updates[chid] = 12 + + # Apply some mocks + self.proto.ap_settings.storage.save_notification = Mock() + self.proto.ap_settings.router.get_uaid = mock_get = Mock() + self.proto.ps.metrics = mock_metrics = Mock() + + def raise_item(*args, **kwargs): + raise ItemNotFound() + + mock_get.side_effect = raise_item + + # Close the connection + self.proto.onClose(True, None, None) + + d = Deferred() + + def wait_for_agent_call(): # pragma: nocover + if not mock_metrics.mock_calls: + reactor.callLater(0.1, wait_for_agent_call) + + mock_metrics.increment.assert_called_with( + "client.lookup_uaid_failure", tags=None) d.callback(True) reactor.callLater(0.1, wait_for_agent_call) return d diff --git a/autopush/websocket.py b/autopush/websocket.py index 241325e6..036da9a6 100644 --- a/autopush/websocket.py +++ b/autopush/websocket.py @@ -579,14 +579,22 @@ def _lookup_node(self, results): self.ps.uaid ) d.addCallback(self._notify_node) + d.addErrback(self._trap_uaid_not_found) d.addErrback(self.log_failure, extra="Failed to get UAID for redeliver") + def _trap_uaid_not_found(self, fail): + # type: (Failure) -> None + """Traps UAID not found error""" + fail.trap(ItemNotFound) + self.ps.metrics.increment("client.lookup_uaid_failure", + tags=self.base_tags) + def _notify_node(self, result): """Checks the result of lookup node to send the notify if the client is connected elsewhere now""" if not result: - self.ps.metrics.increment("error.notify_uaid_failure", + self.ps.metrics.increment("client.notify_uaid_failure", tags=self.base_tags) return diff --git a/tox.ini b/tox.ini index 3d738dd9..76aadd73 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ deps = -rtest-requirements.txt usedevelop = True passenv = SKIP_INTEGRATION commands = - nosetests {posargs} --with-object-tracker autopush + nosetests {posargs} autopush install_command = pip install --pre {opts} {packages} [testenv:pypy]