Merge lp:~facundo/magicicada-gui/fix-mq-asking into lp:magicicada-gui

Proposed by Facundo Batista
Status: Merged
Approved by: Natalia Bidart
Approved revision: 75
Merged at revision: 75
Proposed branch: lp:~facundo/magicicada-gui/fix-mq-asking
Merge into: lp:magicicada-gui
Diff against target: 55 lines (+25/-2)
2 files modified
magicicada/syncdaemon.py (+7/-1)
magicicada/tests/test_syncdaemon.py (+18/-1)
To merge this branch: bzr merge lp:~facundo/magicicada-gui/fix-mq-asking
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+39260@code.launchpad.net

Commit message

Leave the "don't ask while asking" machinery ok if error while asking.

Description of the change

Leave the "don't ask while asking" machinery ok if error while asking.

We shouldn't have errors while asking, but if they happen (a new kind of message in MQ, for instance), the machinery was left in a wrong state, and no further MQ asking were done. This branch fixes it.

Test included.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Good catch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magicicada/syncdaemon.py'
2--- magicicada/syncdaemon.py 2010-10-14 03:48:37 +0000
3+++ magicicada/syncdaemon.py 2010-10-25 10:52:44 +0000
4@@ -271,7 +271,13 @@
5 self._must_poll_mq = False
6 self._mq_asking = ASKING_YES
7 while self._mq_asking != ASKING_IDLE:
8- yield self._get_mq_data()
9+ try:
10+ yield self._get_mq_data()
11+ except Exception:
12+ # on any error, leave the state sane
13+ self._mq_asking = ASKING_IDLE
14+ raise
15+
16 if self._mq_asking == ASKING_LATER:
17 self._mq_asking = ASKING_YES
18 else:
19
20=== modified file 'magicicada/tests/test_syncdaemon.py'
21--- magicicada/tests/test_syncdaemon.py 2010-10-14 03:48:37 +0000
22+++ magicicada/tests/test_syncdaemon.py 2010-10-25 10:52:44 +0000
23@@ -22,7 +22,7 @@
24 import os
25 import unittest
26
27-from magicicada.syncdaemon import SyncDaemon, State
28+from magicicada.syncdaemon import SyncDaemon, State, ASKING_IDLE
29 from magicicada.tests.helpers import MementoHandler
30
31 from twisted.trial.unittest import TestCase as TwistedTestCase
32@@ -773,6 +773,23 @@
33 # it should be called three times total
34 self.assertEqual(len(called), 3)
35
36+ @defer.inlineCallbacks
37+ def test_mq_multiple_support_error(self):
38+ """Leave the state ok even with an error in the underlying call."""
39+ def fake():
40+ """Fake."""
41+ raise ValueError('foo')
42+ self.sd.dbus.get_meta_queue = fake
43+
44+ # call it, and "absorb" the error we just generated
45+ try:
46+ yield self.sd.on_sd_meta_queue_changed()
47+ except ValueError:
48+ pass
49+
50+ # it should be in IDLE
51+ self.assertEqual(self.sd._mq_asking, ASKING_IDLE)
52+
53
54 class StateTests(unittest.TestCase):
55 """Test State class."""

Subscribers

People subscribed via source and target branches