summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-03-02 15:00:12 -0400
committerKali Kaneko <kali@leap.se>2015-03-03 14:30:18 -0400
commitbd5f777ff5e9f4fd81afeebb17074326b2671cd1 (patch)
treead52a26e4431c4e7858f17cfc20f0243f64a2fa2
parent0f491cc4f94c00cd9c6e2afe7e3163dfaaad3714 (diff)
[bug] Fix testExpunge tests
this test was failing randomly because we were returning the deferred before all the documents were saved into soledad store. changed also the delete_msg deferred chaining for better readability. Releases: 0.9.0
-rw-r--r--src/leap/mail/imap/mailbox.py29
-rw-r--r--src/leap/mail/imap/tests/test_imap.py10
-rw-r--r--src/leap/mail/mail.py9
3 files changed, 31 insertions, 17 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index 91c6549..61baca5 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/src/leap/mail/imap/mailbox.py
@@ -307,7 +307,7 @@ class IMAPMailbox(object):
d.addCallback(as_a_dict)
return d
- def addMessage(self, message, flags, date=None):
+ def addMessage(self, message, flags, date=None, notify_just_mdoc=True):
"""
Adds a message to this mailbox.
@@ -327,6 +327,21 @@ class IMAPMailbox(object):
# TODO have a look at the cases for internal date in the rfc
# XXX we could treat the message as an IMessage from here
+ # TODO notify_just_mdoc *sometimes* make the append tests fail.
+ # have to find a better solution for this. A workaround could probably
+ # be to have a list of the ongoing deferreds related to append, so that
+ # we queue for later all the requests having to do with these.
+
+ # notify_just_mdoc=True: feels HACKY, but improves a *lot* the
+ # responsiveness of the APPENDS: we just need to be notified when the
+ # mdoc is saved, and let's hope that the other parts are doing just
+ # fine. This will not catch any errors when the inserts of the other
+ # parts fail, but on the other hand allows us to return very quickly,
+ # which seems a good compromise given that we have to serialize the
+ # appends.
+ # A better solution will probably involve implementing MULTIAPPEND
+ # extension or patching imap server to support pipelining.
+
if isinstance(message, (cStringIO.OutputType, StringIO.StringIO)):
message = message.getvalue()
@@ -340,19 +355,9 @@ class IMAPMailbox(object):
if date is None:
date = formatdate(time.time())
- # notify_just_mdoc=True: feels HACKY, but improves a *lot* the
- # responsiveness of the APPENDS: we just need to be notified when the
- # mdoc is saved, and let's hope that the other parts are doing just
- # fine. This will not catch any errors when the inserts of the other
- # parts fail, but on the other hand allows us to return very quickly,
- # which seems a good compromise given that we have to serialize the
- # appends.
- # A better solution will probably involve implementing MULTIAPPEND
- # extension or patching imap server to support pipelining.
-
# TODO add notify_new as a callback here...
return self.collection.add_msg(message, flags, date=date,
- notify_just_mdoc=True)
+ notify_just_mdoc=notify_just_mdoc)
def notify_new(self, *args):
"""
diff --git a/src/leap/mail/imap/tests/test_imap.py b/src/leap/mail/imap/tests/test_imap.py
index a94cea7..c4f752b 100644
--- a/src/leap/mail/imap/tests/test_imap.py
+++ b/src/leap/mail/imap/tests/test_imap.py
@@ -882,6 +882,7 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
"""
Test partially appending a message to the mailbox
"""
+ # TODO this test sometimes will fail because of the notify_just_mdoc
infile = util.sibpath(__file__, 'rfc822.message')
acc = self.server.theAccount
@@ -990,11 +991,14 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
def add_messages():
d = self.mailbox.addMessage(
- 'test 1', flags=('\\Deleted', 'AnotherFlag'))
+ 'test 1', flags=('\\Deleted', 'AnotherFlag'),
+ notify_just_mdoc=False)
d.addCallback(lambda _: self.mailbox.addMessage(
- 'test 2', flags=('AnotherFlag',)))
+ 'test 2', flags=('AnotherFlag',),
+ notify_just_mdoc=False))
d.addCallback(lambda _: self.mailbox.addMessage(
- 'test 3', flags=('\\Deleted',)))
+ 'test 3', flags=('\\Deleted',),
+ notify_just_mdoc=False))
return d
def expunge():
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index 584cc4a..ef9a0d9 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -645,8 +645,13 @@ class MessageCollection(object):
for h in hashes:
d.append(self.mbox_indexer.delete_doc_by_hash(
self.mbox_uuid, h))
- return defer.gatherResults(d).addCallback(
- lambda _: uids)
+
+ def return_uids_when_deleted(ignored):
+ return uids
+
+ all_deleted = defer.gatherResults(d).addCallback(
+ return_uids_when_deleted)
+ return all_deleted
mdocs_deleted = self.adaptor.del_all_flagged_messages(
self.store, self.mbox_uuid)