Merge lp:~facundo/ubuntuone-client/unlock-waiting-for-queue into lp:ubuntuone-client

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 908
Merged at revision: 908
Proposed branch: lp:~facundo/ubuntuone-client/unlock-waiting-for-queue
Merge into: lp:ubuntuone-client
Diff against target: 67 lines (+30/-3)
2 files modified
tests/syncdaemon/test_action_queue.py (+25/-0)
ubuntuone/syncdaemon/action_queue.py (+5/-3)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/unlock-waiting-for-queue
Reviewer Review Type Date Requested Status
Facundo Batista (community) Approve
John O'Brien (community) Approve
Review via email: mp+52422@code.launchpad.net

Commit message

Unlock the wait_for_queue when cancelled. (LP: #729158)

Description of the change

Unlock the wait_for_queue when cancelled.

If the command was waiting for the queue when cancelled, it never released the pathlock, because on cancellation it's removed from the queue, so when the queue become active again it didn't receive the "resume".

Tests included.

To post a comment you must log in.
907. By Facundo Batista

Fixes 729158

Revision history for this message
John O'Brien (jdobrien) wrote :

Looks good and tests pass. You may want to make sure the ActionQueue.cancel doc string is still accurate.

review: Approve
908. By Facundo Batista

Fixed docstring

Revision history for this message
Facundo Batista (facundo) wrote :

Approved with one review.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_action_queue.py'
2--- tests/syncdaemon/test_action_queue.py 2011-03-02 19:21:34 +0000
3+++ tests/syncdaemon/test_action_queue.py 2011-03-07 15:47:26 +0000
4@@ -2092,6 +2092,14 @@
5 self.cmd.cancel()
6 self.assertTrue(d.called)
7
8+ def test_cancel_releases_queue(self):
9+ """Cancel unlocks the wait-for-queue deferred."""
10+ self.cmd.finish = lambda: None # don't try to unqueue!
11+ d = defer.Deferred()
12+ self.cmd.wait_for_queue = d
13+ self.cmd.cancel()
14+ self.assertTrue(d.called)
15+
16 def test_cancel_cancelled(self):
17 """Don't do anything if command already cancelled."""
18 called = []
19@@ -5019,6 +5027,23 @@
20 self._check_finished_ok()
21 self.assertTrue(released)
22
23+ def test_cancel_while_waiting_queue(self):
24+ """Cancel the command while waiting for queue."""
25+ # stop the queue, and fake the pathlock to test releasing
26+ self.queue.active = False
27+ released = []
28+ self.cmd._acquire_pathlock = lambda: defer.succeed(
29+ lambda: released.append(True))
30+
31+ # let the command go (will stuck because not runnable), and
32+ # cancel in the middle
33+ self.cmd.go()
34+ self.cmd.cancel()
35+
36+ # all check
37+ self._check_finished_ok()
38+ self.assertTrue(released)
39+
40 def test_marker_error_while_pathclocked(self):
41 """The marker errbacks while the command is waiting the pathlock."""
42 # monkeypatch methods to flag called and test "while running"
43
44=== modified file 'ubuntuone/syncdaemon/action_queue.py'
45--- ubuntuone/syncdaemon/action_queue.py 2011-03-02 19:21:34 +0000
46+++ ubuntuone/syncdaemon/action_queue.py 2011-03-07 15:47:26 +0000
47@@ -1315,9 +1315,8 @@
48 def cancel(self):
49 """Cancel the command.
50
51- It also triggers the wait_for_condition deferred (but not the
52- wait_for_queue one, as if the queue is not active, it's pointless
53- to release the pathlock for other commands).
54+ Also trigger the wait_for_condition and wait_for_queue deferreds, to
55+ unlock the command and finally release the pathlock.
56
57 Do nothing if already cancelled (as cancellation can come from other
58 thread, it can come at any time, so we need to support double
59@@ -1330,6 +1329,9 @@
60 if self.wait_for_conditions is not None:
61 self.wait_for_conditions.callback(True)
62 self.wait_for_conditions = None
63+ if self.wait_for_queue is not None:
64+ self.wait_for_queue.callback(True)
65+ self.wait_for_queue = None
66 self.cleanup()
67 self.finish()
68

Subscribers

People subscribed via source and target branches