Merge lp:~facundo/ubuntuone-client/stable--query-no-content-file into lp:ubuntuone-client/stable-1-2

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 511
Merged at revision: 512
Proposed branch: lp:~facundo/ubuntuone-client/stable--query-no-content-file
Merge into: lp:ubuntuone-client/stable-1-2
Diff against target: 210 lines (+93/-20)
3 files modified
tests/syncdaemon/test_sync.py (+74/-13)
ubuntuone/syncdaemon/sync.py (+16/-4)
ubuntuone/syncdaemon/u1fsfsm.py (+3/-3)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/stable--query-no-content-file
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Tim Cole (community) Approve
Review via email: mp+25005@code.launchpad.net

Commit message

Queue an upload again on SV_HASH_NEW if being LOCAL with hashes ok.

Description of the change

Queue an upload again on SV_HASH_NEW if being LOCAL with hashes ok.

Refactored the tests a little to include more cases.

This is a backport from trunk.

To post a comment you must log in.
Revision history for this message
Tim Cole (tcole) :
review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Looks good! tests pass.

review: Approve
Revision history for this message
dobey (dobey) wrote :

Attempt to merge lp:~facundo/ubuntuone-client/stable--query-no-content-file into lp:ubuntuone-client/stable-1-2 failed due to merge conflicts:

text conflict in tests/syncdaemon/test_sync.py

511. By Facundo Batista

Merged stable-1-2 in

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

Merged branch back

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_sync.py'
2--- tests/syncdaemon/test_sync.py 2010-05-10 19:15:09 +0000
3+++ tests/syncdaemon/test_sync.py 2010-05-26 18:06:30 +0000
4@@ -30,7 +30,7 @@
5 from contrib.testing.testcase import (
6 FakeVolumeManager,
7 BaseTwistedTestCase,
8- MementoHandler, DummyClass
9+ MementoHandler
10 )
11
12 from contrib.testing import testcase
13@@ -182,8 +182,8 @@
14 self.fsm.get_by_path(path).server_hash)
15
16
17-class TestSync(BaseTwistedTestCase):
18- """Test for Sync."""
19+class BaseSync(BaseTwistedTestCase):
20+ """Base test infrastructure for Sync."""
21
22 def setUp(self):
23 """Init."""
24@@ -220,6 +220,10 @@
25 raise exc_info[0], exc_info[1], exc_info[2]
26 BaseTwistedTestCase.tearDown(self)
27
28+
29+class TestSync(BaseSync):
30+ """Test for Sync."""
31+
32 def test_deleting_open_files_is_no_cause_for_despair(self):
33 """test_deleting_open_files_is_no_cause_for_despair."""
34 def cb(_):
35@@ -258,8 +262,8 @@
36 def faked_nothing(ssmr, event, params, *args):
37 """Wrap SSMR.nothing to test."""
38 self.called = True
39+ self.patch(SyncStateMachineRunner, 'nothing', faked_nothing)
40
41- SyncStateMachineRunner.nothing = faked_nothing
42 kwargs = dict(share_id='share_id', node_id='node_id')
43 sync.handle_AQ_DOWNLOAD_DOES_NOT_EXIST(**kwargs)
44 self.assertTrue(self.called, 'nothing was called')
45@@ -272,7 +276,7 @@
46 def faked_nothing(ssmr, event, params, *args):
47 """Wrap SSMR.nothing to test."""
48 self.called = True
49- SyncStateMachineRunner.nothing = faked_nothing
50+ self.patch(SyncStateMachineRunner, 'nothing', faked_nothing)
51
52 # create a file and put it in local
53 fsm = self.main.fs
54@@ -284,28 +288,85 @@
55 sync.handle_FS_FILE_CREATE(somepath)
56 self.assertTrue(self.called)
57
58-
59-class SyncStateMachineRunnerTestCase(BaseTwistedTestCase):
60+ def test_SV_HASH_NEW_with_file_uploadinterrupted(self):
61+ """A SV_HASH_NEW is received after upload interrupted."""
62+ sync = Sync(main=self.main)
63+ self.called = False
64+
65+ def fake_meth(_, event, params, hash):
66+ """Wrap SSMR.reput_file_from_local to test."""
67+ self.assertEqual(event, 'SV_HASH_NEW')
68+ self.assertEqual(hash, '')
69+ self.called = True
70+ self.patch(SyncStateMachineRunner, 'reput_file_from_local', fake_meth)
71+
72+ # create a file and put it in local, without server_hash, as
73+ # if the upload was cut in the middle after the make file
74+ fsm = self.main.fs
75+ somepath = os.path.join(self.root, 'somepath')
76+ mdid = fsm.create(somepath, '', node_id='node_id')
77+ fsm.set_by_mdid(mdid, local_hash='somehash', crc32='crc32',
78+ stat='stat', size='size')
79+
80+ # send the event and check
81+ mdobj = fsm.get_by_mdid(mdid)
82+ sync.handle_SV_HASH_NEW(mdobj.share_id, mdobj.node_id, '') # no content
83+ self.assertTrue(self.called)
84+
85+
86+class SyncStateMachineRunnerTestCase(BaseSync):
87 """Tests for the SyncStateMachineRunner."""
88
89 def setUp(self):
90 """Init."""
91- BaseTwistedTestCase.setUp(self)
92- self.ssmr = SyncStateMachineRunner(fsm=None, main=None,
93- key=DummyClass(), logger=None)
94+ BaseSync.setUp(self)
95+
96+ # create a file
97+ self.fsm = self.main.fs
98+ somepath = os.path.join(self.root, 'somepath')
99+ self.mdid = self.fsm.create(somepath, '', node_id='node_id')
100+
101+ key = FSKey(self.main.fs, share_id='', node_id='node_id')
102+ self.ssmr = SyncStateMachineRunner(fsm=self.main.fs, main=self.main,
103+ key=key, logger=None)
104
105 def tearDown(self):
106 """Clean up."""
107 self.ssmr = None
108- BaseTwistedTestCase.tearDown(self)
109+ BaseSync.tearDown(self)
110
111- def test_delete_file(self):
112- """delete_file can be called with or without the server hash."""
113+ def test_delete_file_without_hash(self):
114+ """Delete_file can be called without the server hash."""
115 self.ssmr.delete_file(event='AQ_DOWNLOAD_ERROR', params=None)
116
117+ def test_delete_file_with_hash(self):
118+ """Delete_file can be called with the server hash."""
119 self.ssmr.delete_file(event='AQ_DOWNLOAD_ERROR', params=None,
120 server_hash='')
121
122+ def test_put_file_stores_info(self):
123+ """The put_file method should store the info in FSM."""
124+ self.ssmr.put_file('HQ_HASH_NEW', None, 'hash', 'crc', 'size', 'stt')
125+
126+ # check the info is stored
127+ mdobj = self.fsm.get_by_mdid(self.mdid)
128+ self.assertEqual(mdobj.local_hash, 'hash')
129+ self.assertEqual(mdobj.crc32, 'crc')
130+ self.assertEqual(mdobj.size, 'size')
131+ self.assertEqual(mdobj.stat, 'stt')
132+
133+ def test_reput_file_stores_info(self):
134+ """The reput_file method should store the info in FSM."""
135+ self.ssmr.reput_file('HQ_HASH_NEW', None, 'hash', 'crc', 'size', 'stt')
136+
137+ # check the info is stored
138+ mdobj = self.fsm.get_by_mdid(self.mdid)
139+ self.assertEqual(mdobj.local_hash, 'hash')
140+ self.assertEqual(mdobj.crc32, 'crc')
141+ self.assertEqual(mdobj.size, 'size')
142+ self.assertEqual(mdobj.stat, 'stt')
143+
144+
145 class FakedState(object):
146 """A faked state."""
147
148
149=== modified file 'ubuntuone/syncdaemon/sync.py'
150--- ubuntuone/syncdaemon/sync.py 2010-04-08 14:39:27 +0000
151+++ ubuntuone/syncdaemon/sync.py 2010-05-26 18:06:30 +0000
152@@ -669,10 +669,22 @@
153 """Starts the scan again on a dir."""
154 self.m.lr.scan_dir(self.key['mdid'], self.key['path'], udfmode)
155
156+ def reput_file_from_local(self, event, params, hash):
157+ """Re put the file from its local state."""
158+ local_hash = self.key['local_hash']
159+ previous_hash = self.key['server_hash']
160+ crc32 = self.key['crc32']
161+ size = self.key['size']
162+ share_id = self.key['share_id']
163+ node_id = self.key['node_id']
164+
165+ self.m.action_q.upload(share_id, node_id, previous_hash, local_hash,
166+ crc32, size, self.key.open_file)
167+
168 def put_file(self, event, params, hash, crc32, size, stat):
169- """upload the file to the server."""
170+ """Upload the file to the server."""
171 previous_hash = self.key['server_hash']
172- self.key.set(local_hash=hash, stat=stat)
173+ self.key.set(local_hash=hash, stat=stat, crc32=crc32, size=size)
174 self.key.sync()
175
176 self.m.action_q.upload(share_id=self.key['share_id'],
177@@ -699,12 +711,12 @@
178
179
180 def reput_file(self, event, param, hash, crc32, size, stat):
181- """put the file again."""
182+ """Put the file again."""
183 self.m.action_q.cancel_upload(share_id=self.key['share_id'],
184 node_id=self.key['node_id'])
185 previous_hash = self.key['server_hash']
186
187- self.key.set(local_hash=hash, stat=stat)
188+ self.key.set(local_hash=hash, stat=stat, crc32=crc32, size=size)
189 self.key.sync()
190 self.m.action_q.upload(share_id=self.key['share_id'],
191 node_id=self.key['node_id'], previous_hash=previous_hash,
192
193=== modified file 'ubuntuone/syncdaemon/u1fsfsm.ods'
194Binary files ubuntuone/syncdaemon/u1fsfsm.ods 2010-04-23 15:23:09 +0000 and ubuntuone/syncdaemon/u1fsfsm.ods 2010-05-26 18:06:30 +0000 differ
195=== modified file 'ubuntuone/syncdaemon/u1fsfsm.py'
196--- ubuntuone/syncdaemon/u1fsfsm.py 2010-04-23 15:23:09 +0000
197+++ ubuntuone/syncdaemon/u1fsfsm.py 2010-05-26 18:06:30 +0000
198@@ -2445,9 +2445,9 @@
199 'STATE_OUT': {u'changed': u'*',
200 u'has_metadata': u'*',
201 u'is_directory': u'*'}},
202- {'ACTION': u'CONFLICT',
203- 'ACTION_FUNC': u'nothing',
204- 'COMMENTS': u'',
205+ {'ACTION': u'aq.upload()',
206+ 'ACTION_FUNC': u'reput_file_from_local',
207+ 'COMMENTS': u'The upload was interrupted, just try it again. ',
208 'PARAMETERS': {u'hash_eq_local_hash': u'F',
209 u'hash_eq_server_hash': u'T',
210 u'not_authorized': u'NA',

Subscribers

People subscribed via source and target branches