diff options
| author | Barry Warsaw | 2011-05-14 07:06:54 +0200 |
|---|---|---|
| committer | Barry Warsaw | 2011-05-14 07:06:54 +0200 |
| commit | 7af50e2b346b76daab8206c448e5e67f06cbacbd (patch) | |
| tree | 2ad9a9b4f5b30c2e36d6be20fb87d224f047c9af /src/mailman/queue | |
| parent | aba960f1c537ba38217f0377e58d611fcfd8f0a1 (diff) | |
| download | mailman-7af50e2b346b76daab8206c448e5e67f06cbacbd.tar.gz mailman-7af50e2b346b76daab8206c448e5e67f06cbacbd.tar.zst mailman-7af50e2b346b76daab8206c448e5e67f06cbacbd.zip | |
Add tests for the outgoing queue runner.
* Use m.u.datetime.now() instead of datetime.now()
* Add a predicate argument to make_testable_runner() so that we can e.g. pass
in a function that causes the queue runner to run only once.
* Minor improvement to get_queue_messages() so that it doesn't need a lambda.
Diffstat (limited to 'src/mailman/queue')
| -rw-r--r-- | src/mailman/queue/outgoing.py | 9 | ||||
| -rw-r--r-- | src/mailman/queue/tests/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/queue/tests/test_outgoing.py | 87 |
3 files changed, 92 insertions, 4 deletions
diff --git a/src/mailman/queue/outgoing.py b/src/mailman/queue/outgoing.py index 7ff194219..07d45c0bd 100644 --- a/src/mailman/queue/outgoing.py +++ b/src/mailman/queue/outgoing.py @@ -28,6 +28,7 @@ from mailman.interfaces.mailinglist import Personalization from mailman.interfaces.mta import SomeRecipientsFailed from mailman.queue import Runner from mailman.queue.bounce import BounceMixin +from mailman.utilities.datetime import now from mailman.utilities.modules import find_name @@ -56,7 +57,7 @@ class OutgoingRunner(Runner, BounceMixin): def _dispose(self, mlist, msg, msgdata): # See if we should retry delivery of this message again. deliver_after = msgdata.get('deliver_after', datetime.fromtimestamp(0)) - if datetime.now() < deliver_after: + if now() < deliver_after: return True # Calculate whether we should VERP this message or not. The results of # this set the 'verp' key in the message metadata. @@ -118,15 +119,15 @@ class OutgoingRunner(Runner, BounceMixin): # occasionally move them back here for another shot at # delivery. if error.temporary_failures: - now = datetime.now() + current_time = now() recips = error.temporary_failures last_recip_count = msgdata.get('last_recip_count', 0) - deliver_until = msgdata.get('deliver_until', now) + deliver_until = msgdata.get('deliver_until', current_time) if len(recips) == last_recip_count: # We didn't make any progress, so don't attempt # delivery any longer. BAW: is this the best # disposition? - if now > deliver_until: + if current_time > deliver_until: return False else: # Keep trying to delivery this message for a while diff --git a/src/mailman/queue/tests/__init__.py b/src/mailman/queue/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/mailman/queue/tests/__init__.py diff --git a/src/mailman/queue/tests/test_outgoing.py b/src/mailman/queue/tests/test_outgoing.py new file mode 100644 index 000000000..fc4eb3070 --- /dev/null +++ b/src/mailman/queue/tests/test_outgoing.py @@ -0,0 +1,87 @@ +# Copyright (C) 2011 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test the outgoing queue runner.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'test_suite', + ] + + +import datetime +import unittest + +from mailman.app.lifecycle import create_list +from mailman.config import config +from mailman.queue.outgoing import OutgoingRunner +from mailman.testing.helpers import ( + get_queue_messages, + make_testable_runner, + specialized_message_from_string as message_from_string) +from mailman.testing.layers import SMTPLayer +from mailman.utilities.datetime import now + + + +def run_once(qrunner): + """Predicate for make_testable_runner(). + + Ensures that the queue runner only runs once. + """ + return True + + + +class TestOnce(unittest.TestCase): + """Test outgoing runner message disposition.""" + + layer = SMTPLayer + + def setUp(self): + self._mlist = create_list('test@example.com') + self._outq = config.switchboards['out'] + self._runner = make_testable_runner(OutgoingRunner, 'out', run_once) + self._msg = message_from_string("""\ +From: anne@example.com +To: test@example.com +Message-Id: <first> + +""") + self._msgdata = {} + + def test_deliver_after(self): + # When the metadata has a deliver_after key in the future, the queue + # runner will re-enqueue the message rather than delivering it. + deliver_after = now() + datetime.timedelta(days=10) + self._msgdata['deliver_after'] = deliver_after + self._outq.enqueue(self._msg, self._msgdata, tolist=True, + listname='test@example.com') + self._runner.run() + items = get_queue_messages('out') + self.assertEqual(len(items), 1) + self.assertEqual(items[0].msgdata['deliver_after'], deliver_after) + self.assertEqual(items[0].msg['message-id'], '<first>') + + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestOnce)) + return suite |
