[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/mail/ Bugfix: make sure no emails are sent when the transaction fails late during

Marius Gedminas marius at pov.lt
Fri Apr 21 12:43:55 EDT 2006


Log message for revision 67231:
  Bugfix: make sure no emails are sent when the transaction fails late during
  two-phase commit.
  
  This fixes one part of http://www.zope.org/Collectors/Zope3-dev/590.
  
  

Changed:
  U   Zope3/trunk/src/zope/app/mail/delivery.py
  U   Zope3/trunk/src/zope/app/mail/tests/test_delivery.py

-=-
Modified: Zope3/trunk/src/zope/app/mail/delivery.py
===================================================================
--- Zope3/trunk/src/zope/app/mail/delivery.py	2006-04-21 16:40:03 UTC (rev 67230)
+++ Zope3/trunk/src/zope/app/mail/delivery.py	2006-04-21 16:43:55 UTC (rev 67231)
@@ -48,7 +48,7 @@
         self.transaction_manager = transaction.manager
 
     def commit(self, transaction):
-        self.callable(*self.args)
+        pass
 
     def abort(self, transaction):
          if self.onAbort:
@@ -74,9 +74,12 @@
     def tpc_vote(self, transaction):
         pass
 
-    tpc_finish = tpc_abort = tpc_vote
+    def tpc_finish(self, transaction):
+        self.callable(*self.args)
 
+    tpc_abort = abort
 
+
 class AbstractMailDelivery(object):
 
     def newMessageId(self):

Modified: Zope3/trunk/src/zope/app/mail/tests/test_delivery.py
===================================================================
--- Zope3/trunk/src/zope/app/mail/tests/test_delivery.py	2006-04-21 16:40:03 UTC (rev 67230)
+++ Zope3/trunk/src/zope/app/mail/tests/test_delivery.py	2006-04-21 16:43:55 UTC (rev 67231)
@@ -23,6 +23,7 @@
 from unittest import TestCase, TestSuite, makeSuite
 
 import transaction
+from zope.testing import doctest
 from zope.interface import implements
 from zope.interface.verify import verifyObject
 from zope.app.mail.interfaces import IMailer
@@ -49,6 +50,47 @@
         self.assertEqual(manager.args, (1, 2))
 
 
+def print_success(*args):
+    print "message successfully sent, args: %s" % (args, )
+
+def print_abort():
+    print "message aborted"
+
+
+def doctest_successful_commit():
+    """Regression test for http://www.zope.org/Collectors/Zope3-dev/590
+
+    Let's do a full two-phase commit.
+
+        >>> from zope.app.mail.delivery import MailDataManager
+        >>> manager = MailDataManager(print_success, ('foo', 'bar'),
+        ...                           onAbort=print_abort)
+        >>> transaction = object()
+        >>> manager.tpc_begin(transaction)
+        >>> manager.commit(transaction)
+        >>> manager.tpc_vote(transaction)
+        >>> manager.tpc_finish(transaction)
+        message successfully sent, args: ('foo', 'bar')
+
+    """
+
+
+def doctest_unsuccessful_commit():
+    """Regression test for http://www.zope.org/Collectors/Zope3-dev/590
+
+    Let's start a two-phase commit, then abort it.
+
+        >>> from zope.app.mail.delivery import MailDataManager
+        >>> manager = MailDataManager(print_success, onAbort=print_abort)
+        >>> manager.tpc_begin(transaction)
+        >>> manager.commit(transaction)
+        >>> manager.tpc_vote(transaction)
+        >>> manager.tpc_abort(transaction)
+        message aborted
+
+    """
+
+
 class TestDirectMailDelivery(TestCase):
 
     def testInterface(self):
@@ -297,6 +339,7 @@
         makeSuite(TestDirectMailDelivery),
         makeSuite(TestQueuedMailDelivery),
         makeSuite(TestQueueProcessorThread),
+        doctest.DocTestSuite(),
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list