Merge lp:~facundo/ubuntuone-client/reset-written-bytes into lp:ubuntuone-client

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 911
Merged at revision: 913
Proposed branch: lp:~facundo/ubuntuone-client/reset-written-bytes
Merge into: lp:ubuntuone-client
Diff against target: 48 lines (+19/-1)
2 files modified
tests/syncdaemon/test_action_queue.py (+17/-0)
ubuntuone/syncdaemon/action_queue.py (+2/-1)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/reset-written-bytes
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Lucio Torre (community) Approve
Review via email: mp+52693@code.launchpad.net

Commit message

Reset the written values in Upload to 0 when re-run (LP: #724532)

Description of the change

Reset the written values in Upload to 0 when re-run

The command can be interrupted and tried again, so needs to reset the values on each _run(). Note that they are reset to 0, but if the Upload is multipart it will then adjust the values in UploadProgressWrapper.seek().

Also, moved the responsibility of the reset to UploadProgressWrapper, because it already was handling these values.

Test included.

To post a comment you must log in.
Revision history for this message
Lucio Torre (lucio.torre) :
review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) :
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-07 16:54:25 +0000
3+++ tests/syncdaemon/test_action_queue.py 2011-03-09 14:56:59 +0000
4@@ -3037,6 +3037,23 @@
5 class UploadProgressWrapperTestCase(BaseTwistedTestCase):
6 """Test for the UploadProgressWrapper helper class."""
7
8+ def test_reset(self):
9+ """Reset the values at start."""
10+ f = StringIO("x" * 10 + "y" * 5)
11+ cmd = FakeCommand()
12+
13+ # first time
14+ UploadProgressWrapper(f, cmd)
15+ self.assertEqual(cmd.n_bytes_written, 0)
16+ self.assertEqual(cmd.n_bytes_written_last, 0)
17+
18+ # fake as it worked a little, was interrupted, and tried again
19+ cmd.n_bytes_written_last = 1234
20+ cmd.n_bytes_written = 1248
21+ UploadProgressWrapper(f, cmd)
22+ self.assertEqual(cmd.n_bytes_written, 0)
23+ self.assertEqual(cmd.n_bytes_written_last, 0)
24+
25 def test_read(self):
26 """Test the read method."""
27 class FakeCommand(object):
28
29=== modified file 'ubuntuone/syncdaemon/action_queue.py'
30--- ubuntuone/syncdaemon/action_queue.py 2011-03-07 16:54:25 +0000
31+++ ubuntuone/syncdaemon/action_queue.py 2011-03-09 14:56:59 +0000
32@@ -570,6 +570,8 @@
33 def __init__(self, fd, command):
34 self.fd = fd
35 self.command = command
36+ self.command.n_bytes_written = 0
37+ self.command.n_bytes_written_last = 0
38
39 def read(self, size=None):
40 """Read at most size bytes from the file-like object.
41@@ -2401,7 +2403,6 @@
42
43 if getattr(self.tempfile, 'name', None) is not None:
44 self.tempfile = open(self.tempfile.name)
45- self.n_bytes_written_last = 0
46 f = UploadProgressWrapper(self.tempfile, self)
47
48 # access here the magic hash value, don't log anywhere, and

Subscribers

People subscribed via source and target branches