Merge lp:~alecu/ubuntuone-client/fix-download-finished into lp:ubuntuone-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 1288
Merged at revision: 1289
Proposed branch: lp:~alecu/ubuntuone-client/fix-download-finished
Merge into: lp:ubuntuone-client
Diff against target: 178 lines (+61/-23)
5 files modified
tests/syncdaemon/test_fsm.py (+27/-0)
tests/syncdaemon/test_interaction_interfaces.py (+28/-20)
ubuntuone/syncdaemon/event_queue.py (+1/-0)
ubuntuone/syncdaemon/filesystem_manager.py (+3/-1)
ubuntuone/syncdaemon/interaction_interfaces.py (+2/-2)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/fix-download-finished
Reviewer Review Type Date Requested Status
Brian Curtin (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+118759@code.launchpad.net

Commit message

- DownloadFinished ipc signal is now thrown after the partial is commited. (LP: #1031197)

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve
1288. By Alejandro J. Cura

fixing comment

Revision history for this message
Brian Curtin (brian.curtin) wrote :

Approved, but with a minor nit-pick that's not enough to really hold this up:

32 + kwargs = dict(share_id=mdobj.share_id, node_id=mdobj.node_id)

Any reason not to use a dict literal there?

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_fsm.py'
2--- tests/syncdaemon/test_fsm.py 2012-04-09 20:07:05 +0000
3+++ tests/syncdaemon/test_fsm.py 2012-08-08 18:38:19 +0000
4@@ -1626,6 +1626,33 @@
5 mdobj = self.fsm.get_by_mdid(mdid)
6 self.assertEqual(mdobj.stat, stat_path(path))
7
8+ def test_commit_partial_pushes_event(self):
9+ """Test that the right event is pushed after the commit."""
10+ listener = Listener()
11+ self.eq.subscribe(listener)
12+
13+ path = os.path.join(self.share.path, "thisfile")
14+ open_file(path, "w").close()
15+ mdobj = self.create_node("thisfile")
16+ mdid = mdobj.mdid
17+ oldstat = stat_path(path)
18+ self.assertEqual(mdobj.stat, oldstat)
19+
20+ # create a partial
21+ self.fsm.create_partial(mdobj.node_id, mdobj.share_id)
22+ fh = self.fsm.get_partial_for_writing(mdobj.node_id, mdobj.share_id)
23+ fh.write("foobar")
24+ fh.close()
25+ mdobj = self.fsm.get_by_mdid(mdid)
26+ self.assertEqual(mdobj.stat, oldstat)
27+
28+ # commit the partial
29+ self.fsm.commit_partial(mdobj.node_id, mdobj.share_id, "localhash")
30+ mdobj = self.fsm.get_by_mdid(mdid)
31+
32+ kwargs = dict(share_id=mdobj.share_id, node_id=mdobj.node_id)
33+ self.assertTrue(("FSM_PARTIAL_COMMITED", kwargs) in listener.events)
34+
35 def test_move(self):
36 """Test that move refreshes stat."""
37 path1 = os.path.join(self.share.path, "thisfile1")
38
39=== modified file 'tests/syncdaemon/test_interaction_interfaces.py'
40--- tests/syncdaemon/test_interaction_interfaces.py 2012-04-09 20:07:05 +0000
41+++ tests/syncdaemon/test_interaction_interfaces.py 2012-08-08 18:38:19 +0000
42@@ -1226,18 +1226,19 @@
43 self.addCleanup(self.main.event_q.unsubscribe, self.sd_obj)
44
45
46-class DownloadTestCase(SyncdaemonEventListenerTestCase):
47- """Test the Download events in SyncdaemonEventListener."""
48+class UploadTestCase(SyncdaemonEventListenerTestCase):
49+ """Test the Upload events in SyncdaemonEventListener."""
50
51 add_fsm_key = True
52- direction = 'Download'
53- bytes_key = 'n_bytes_read'
54- hash_kwarg = 'server_hash'
55- extra_finished_args = {}
56+ direction = 'Upload'
57+ bytes_key = 'n_bytes_written'
58+ hash_kwarg = 'hash'
59+ extra_finished_args = dict(new_generation='new_generation', hash='')
60+ finished_event = 'AQ_UPLOAD_FINISHED'
61
62 @defer.inlineCallbacks
63 def setUp(self):
64- yield super(DownloadTestCase, self).setUp()
65+ yield super(UploadTestCase, self).setUp()
66 self.deferred = None
67 self.signal_name = None
68 if self.add_fsm_key:
69@@ -1304,7 +1305,7 @@
70 return self.deferred
71
72 def test_handle_finished(self):
73- """Test the handle_AQ_<direction>_FINISHED method."""
74+ """Test the handle_<finished_event> method."""
75 self.signal_name = self.direction + 'Finished'
76 self.deferred = defer.Deferred()
77
78@@ -1320,10 +1321,9 @@
79 self.patch(self.sd_obj.interface.status, 'SignalError',
80 self.error_handler)
81
82- kwargs = {'share_id': '', 'node_id': 'node_id', self.hash_kwarg: ''}
83+ kwargs = {'share_id': '', 'node_id': 'node_id'}
84 kwargs.update(self.extra_finished_args)
85- self.main.event_q.push('AQ_%s_FINISHED' % self.direction.upper(),
86- **kwargs)
87+ self.main.event_q.push(self.finished_event, **kwargs)
88 return self.deferred
89
90 def test_handle_event_error(self):
91@@ -1350,21 +1350,29 @@
92 return self.deferred
93
94
95+class DownloadTestCase(UploadTestCase):
96+ """Test the Download events in SyncdaemonEventListener."""
97+
98+ direction = 'Download'
99+ bytes_key = 'n_bytes_read'
100+ hash_kwarg = 'server_hash'
101+ extra_finished_args = {}
102+ finished_event = 'FSM_PARTIAL_COMMITED'
103+
104+ # The download is special, because we don't want to throw the ipc signal on
105+ # AQ_DOWNLOAD_FINISHED but instead we should wait for FSM_PARTIAL_COMMITED
106+
107+ def test_ignore_pre_partial_commit_event(self):
108+ """The AQ_DOWNLOAD_FINISHED signal is ignored."""
109+ self.assertNotIn("handle_AQ_DOWNLOAD_FINISHED", vars(self.sd_class))
110+
111+
112 class DownloadNoKeyTestCase(DownloadTestCase):
113 """Test the Download events when there is a fsm KeyError."""
114
115 add_fsm_key = False
116
117
118-class UploadTestCase(DownloadTestCase):
119- """Test the Upload events in SyncdaemonEventListener."""
120-
121- direction = 'Upload'
122- bytes_key = 'n_bytes_written'
123- hash_kwarg = 'hash'
124- extra_finished_args = dict(new_generation='new_generation')
125-
126-
127 class UploadNoKeyTestCase(UploadTestCase):
128 """Test the Upload events when there is a fsm KeyError."""
129
130
131=== modified file 'ubuntuone/syncdaemon/event_queue.py'
132--- ubuntuone/syncdaemon/event_queue.py 2012-07-31 08:26:30 +0000
133+++ ubuntuone/syncdaemon/event_queue.py 2012-08-08 18:38:19 +0000
134@@ -159,6 +159,7 @@
135
136 'FSM_FILE_CONFLICT': ('old_name', 'new_name'),
137 'FSM_DIR_CONFLICT': ('old_name', 'new_name'),
138+ 'FSM_PARTIAL_COMMITED': ('share_id', 'node_id'),
139
140 'VM_UDF_SUBSCRIBED': ('udf',),
141 'VM_UDF_SUBSCRIBE_ERROR': ('udf_id', 'error'),
142
143=== modified file 'ubuntuone/syncdaemon/filesystem_manager.py'
144--- ubuntuone/syncdaemon/filesystem_manager.py 2012-06-22 11:29:10 +0000
145+++ ubuntuone/syncdaemon/filesystem_manager.py 2012-08-08 18:38:19 +0000
146@@ -1142,7 +1142,7 @@
147 return fd
148
149 def commit_partial(self, node_id, share_id, local_hash):
150- """Create a .partial in disk and set the flag in metadata."""
151+ """Commit a file from a .partial to disk."""
152 mdid = self._idx_node_id[(share_id, node_id)]
153 mdobj = self.fs[mdid]
154 if mdobj["is_dir"]:
155@@ -1166,6 +1166,8 @@
156 mdobj["info"]["is_partial"] = False
157 mdobj["stat"] = get_stat(path)
158 self.fs[mdid] = mdobj
159+ self.eq.push("FSM_PARTIAL_COMMITED", share_id=share_id,
160+ node_id=node_id)
161
162 def remove_partial(self, node_id, share_id):
163 """Remove a .partial in disk and set the flag in metadata."""
164
165=== modified file 'ubuntuone/syncdaemon/interaction_interfaces.py'
166--- ubuntuone/syncdaemon/interaction_interfaces.py 2012-05-22 14:07:55 +0000
167+++ ubuntuone/syncdaemon/interaction_interfaces.py 2012-08-08 18:38:19 +0000
168@@ -816,8 +816,8 @@
169 self._path_from_ids(share_id, node_id, 'DownloadFileProgress', info)
170
171 @log_call(logger.debug)
172- def handle_AQ_DOWNLOAD_FINISHED(self, share_id, node_id, server_hash):
173- """Handle AQ_DOWNLOAD_FINISHED."""
174+ def handle_FSM_PARTIAL_COMMITED(self, share_id, node_id):
175+ """Handle FSM_PARTIAL_COMMITED."""
176 self._path_from_ids(share_id, node_id, 'DownloadFinished', info={})
177
178 @log_call(logger.debug)

Subscribers

People subscribed via source and target branches