]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_system.py: remove that ugly debug_stash_RemoteencryptedUploadable hack, now...
authorBrian Warner <warner@allmydata.com>
Fri, 8 Feb 2008 00:27:30 +0000 (17:27 -0700)
committerBrian Warner <warner@allmydata.com>
Fri, 8 Feb 2008 00:27:30 +0000 (17:27 -0700)
src/allmydata/test/test_system.py
src/allmydata/upload.py

index 59bc91124ac5552cd9b68af3816b43e6df33fc98..80fcb7f58b6aeb093afbf87158326669b82b66c4 100644 (file)
@@ -32,6 +32,13 @@ This is some data to publish to the virtual drive, which needs to be large
 enough to not fit inside a LIT uri.
 """
 
+class CountingDataUploadable(upload.Data):
+    bytes_read = 0
+    def read(self, length):
+        self.bytes_read += length
+        return upload.Data.read(self, length)
+
+
 class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
 
     def setUp(self):
@@ -325,13 +332,12 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
 
         def _upload_resumable(res):
             DATA = "Data that needs help to upload and gets interrupted" * 1000
-            u1 = upload.Data(DATA, contenthashkey=contenthashkey)
-            u2 = upload.Data(DATA, contenthashkey=contenthashkey)
+            u1 = CountingDataUploadable(DATA, contenthashkey=contenthashkey)
+            u2 = CountingDataUploadable(DATA, contenthashkey=contenthashkey)
 
             # tell the upload to drop the connection after about 5kB
             u1.debug_interrupt = 5000
-            u1.debug_stash_RemoteEncryptedUploadable = True
-            u2.debug_stash_RemoteEncryptedUploadable = True
+
             # sneak into the helper and reduce its chunk size, so that our
             # debug_interrupt will sever the connection on about the fifth
             # chunk fetched. This makes sure that we've started to write the
@@ -348,12 +354,13 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
                           " with result %s" % (res,))
             def _interrupted(f):
                 f.trap(ConnectionLost, ConnectionDone, DeadReferenceError)
-                reu = u1.debug_RemoteEncryptedUploadable
+
                 # make sure we actually interrupted it before finishing the
                 # file
-                self.failUnless(reu._bytes_sent < len(DATA),
-                                "read %d out of %d total" % (reu._bytes_sent,
+                self.failUnless(u1.bytes_read < len(DATA),
+                                "read %d out of %d total" % (u1.bytes_read,
                                                              len(DATA)))
+
                 log.msg("waiting for reconnect", level=log.NOISY,
                         facility="tahoe.test.test_system")
                 # now, we need to give the nodes a chance to notice that this
@@ -397,7 +404,10 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
                 uri = results.uri
                 log.msg("Second upload complete", level=log.NOISY,
                         facility="tahoe.test.test_system")
-                reu = u2.debug_RemoteEncryptedUploadable
+
+                # this is really bytes received rather than sent, but it's
+                # convenient and basically measures the same thing
+                bytes_sent = results.ciphertext_fetched
 
                 # We currently don't support resumption of upload if the data is
                 # encrypted with a random key.  (Because that would require us
@@ -407,18 +417,18 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
                 if contenthashkey:
                     # Make sure we did not have to read the whole file the
                     # second time around .
-                    self.failUnless(reu._bytes_sent < len(DATA),
+                    self.failUnless(bytes_sent < len(DATA),
                                 "resumption didn't save us any work:"
                                 " read %d bytes out of %d total" %
-                                (reu._bytes_sent, len(DATA)))
+                                (bytes_sent, len(DATA)))
                 else:
                     # Make sure we did have to read the whole file the second
                     # time around -- because the one that we partially uploaded
                     # earlier was encrypted with a different random key.
-                    self.failIf(reu._bytes_sent < len(DATA),
+                    self.failIf(bytes_sent < len(DATA),
                                 "resumption saved us some work even though we were using random keys:"
                                 " read %d bytes out of %d total" %
-                                (reu._bytes_sent, len(DATA)))
+                                (bytes_sent, len(DATA)))
                 return self.downloader.download_to_data(uri)
             d.addCallback(_uploaded)
 
index d852f6f1cf2522bf52b223afe5ef6eabc56d704d..ebf21b1825cd4cc4dc5c40c79529eea8cc70d839 100644 (file)
@@ -840,16 +840,6 @@ class AssistedUploader:
             # we have unit tests which want to interrupt the upload so they
             # can exercise resumability. They indicate this by adding debug_
             # attributes to the Uploadable.
-            if hasattr(self._encuploadable.original,
-                       "debug_stash_RemoteEncryptedUploadable"):
-                # we communicate back to them the same way. This may look
-                # weird, but, well, ok, it is. However, it is better than the
-                # barrage of options={} dictionaries that were flying around
-                # before. We could also do this by setting attributes on the
-                # class, but that doesn't make it easy to undo when we're
-                # done. TODO: find a cleaner way, maybe just a small options=
-                # dict somewhere.
-                self._encuploadable.original.debug_RemoteEncryptedUploadable = reu
             if hasattr(self._encuploadable.original, "debug_interrupt"):
                 reu._cutoff = self._encuploadable.original.debug_interrupt
                 def _cutoff():