diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/adapter/listeners/mailbox_indexer_listener.py | 18 | ||||
-rw-r--r-- | service/test/unit/adapter/test_mailbox_indexer_listener.py | 16 |
2 files changed, 26 insertions, 8 deletions
diff --git a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py index 77a78f0e..8896d742 100644 --- a/service/pixelated/adapter/listeners/mailbox_indexer_listener.py +++ b/service/pixelated/adapter/listeners/mailbox_indexer_listener.py @@ -13,10 +13,13 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. - +import logging from twisted.internet import defer +logger = logging.getLogger(__name__) + + class MailboxIndexerListener(object): """ Listens for new mails, keeping the index updated """ @@ -38,13 +41,16 @@ class MailboxIndexerListener(object): @defer.inlineCallbacks def newMessages(self, exists, recent): - indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower(), all_mails=True)) - soledad_idents = yield self.mail_store.get_mailbox_mail_ids(self.mailbox_name) - soledad_idents = set(soledad_idents) + try: + indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower(), all_mails=True)) + soledad_idents = yield self.mail_store.get_mailbox_mail_ids(self.mailbox_name) + soledad_idents = set(soledad_idents) - missing_idents = soledad_idents.difference(indexed_idents) + missing_idents = soledad_idents.difference(indexed_idents) - self.SEARCH_ENGINE.index_mails((yield self.mail_store.get_mails(missing_idents))) + self.SEARCH_ENGINE.index_mails((yield self.mail_store.get_mails(missing_idents))) + except Exception, e: # this is a event handler, don't let exceptions escape + logger.error(e) def __eq__(self, other): return other and other.mailbox_name == self.mailbox_name diff --git a/service/test/unit/adapter/test_mailbox_indexer_listener.py b/service/test/unit/adapter/test_mailbox_indexer_listener.py index d107c68a..9ad3c94d 100644 --- a/service/test/unit/adapter/test_mailbox_indexer_listener.py +++ b/service/test/unit/adapter/test_mailbox_indexer_listener.py @@ -13,10 +13,13 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -import unittest +from twisted.trial import unittest -from mockito import mock, when, verify +from mockito import mock, when, verify, any as ANY from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerListener +from twisted.internet import defer + +from pixelated.adapter.listeners.mailbox_indexer_listener import logger class MailboxListenerTest(unittest.TestCase): @@ -52,3 +55,12 @@ class MailboxListenerTest(unittest.TestCase): verify(self.mail_store, times=1).get_mails('INBOX') self.assertIn({'missing_ident'}, self.mail_store.used_arguments) + + @defer.inlineCallbacks + def test_catches_exceptions_to_not_break_other_listeners(self): + when(logger).error(ANY()).thenReturn(None) + listener = MailboxIndexerListener('INBOX', self.mail_store) + + yield listener.newMessages(1, 1) + + verify(logger).error(ANY()) |