]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
storage.py: more test coverage, make sure leases survive resizing
authorBrian Warner <warner@allmydata.com>
Wed, 31 Oct 2007 19:07:47 +0000 (12:07 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 31 Oct 2007 19:07:47 +0000 (12:07 -0700)
src/allmydata/storage.py
src/allmydata/test/test_storage.py

index f8caa72fa3861b712bf32ebcf0f954ea7eefe44a..2ae8521c2ca0ae326260a2e8efcead97610a5947 100644 (file)
@@ -447,7 +447,7 @@ class MutableShareFile(Referenceable):
                 return i
         return None
 
-    def enumerate_leases(self, f):
+    def _enumerate_leases(self, f):
         """Yields (leasenum, (ownerid, expiration_time, renew_secret,
         cancel_secret, accepting_nodeid)) for all leases."""
         for i in range(self._get_num_lease_slots(f)):
@@ -458,6 +458,12 @@ class MutableShareFile(Referenceable):
             except IndexError:
                 return
 
+    def debug_enumerate_leases(self):
+        f = open(self.home, 'rb')
+        leases = list(self._enumerate_leases(f))
+        f.close()
+        return leases
+
     def add_lease(self, lease_info):
         f = open(self.home, 'rb+')
         num_lease_slots = self._get_num_lease_slots(f)
@@ -471,7 +477,7 @@ class MutableShareFile(Referenceable):
     def renew_lease(self, renew_secret, new_expire_time):
         accepting_nodeids = set()
         f = open(self.home, 'rb+')
-        for (leasenum,(oid,et,rs,cs,anid)) in self.enumerate_leases(f):
+        for (leasenum,(oid,et,rs,cs,anid)) in self._enumerate_leases(f):
             if rs == renew_secret:
                 # yup. See if we need to update the owner time.
                 if new_expire_time > et:
@@ -510,7 +516,7 @@ class MutableShareFile(Referenceable):
         blank = "\x00"*32
         blank_lease = (0, 0, blank, blank, blank)
         f = open(self.home, 'rb+')
-        for (leasenum,(oid,et,rs,cs,anid)) in self.enumerate_leases(f):
+        for (leasenum,(oid,et,rs,cs,anid)) in self._enumerate_leases(f):
             accepting_nodeids.add(anid)
             if cs == cancel_secret:
                 self._write_lease_record(f, leasenum, blank_lease)
index bc2258ae281a07c80271fd4548f4be078fbb1153..27b39e6ea42d1b2ec4120655b28d2cc7b2ebe94d 100644 (file)
@@ -724,6 +724,9 @@ class MutableServer(unittest.TestCase):
         # cancel one of them
         ss.remote_cancel_lease("si1", self.cancel_secret(secret+5))
 
+        all_leases = s0.debug_enumerate_leases()
+        self.failUnlessEqual(len(all_leases), 5)
+
         # and write enough data to expand the container, forcing the server
         # to move the leases
         answer = s0.remote_testv_and_writev(WE,
@@ -731,8 +734,9 @@ class MutableServer(unittest.TestCase):
                                             [(0, data),],
                                             new_length=200)
 
-        # TODO: read back the leases, make sure they're still intact. We need
-        # a renew_lease() call for this.
+        # read back the leases, make sure they're still intact.
+        self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+
         ss.remote_renew_lease("si1", self.renew_secret(secret))
         ss.remote_renew_lease("si1", self.renew_secret(secret+1))
         ss.remote_renew_lease("si1", self.renew_secret(secret+2))
@@ -751,14 +755,29 @@ class MutableServer(unittest.TestCase):
                               ss.remote_cancel_lease, "si1",
                               self.cancel_secret(secret+20))
 
+        self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+        answer = s0.remote_testv_and_writev(WE,
+                                            [],
+                                            [(200, "make me bigger"),],
+                                            new_length=None)
+        self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+
+        answer = s0.remote_testv_and_writev(WE,
+                                            [],
+                                            [(500, "make me really bigger"),],
+                                            new_length=None)
+        self.failUnlessEqual(all_leases, s0.debug_enumerate_leases())
+
         # now cancel them all
         ss.remote_cancel_lease("si1", self.cancel_secret(secret))
         ss.remote_cancel_lease("si1", self.cancel_secret(secret+1))
         ss.remote_cancel_lease("si1", self.cancel_secret(secret+2))
         ss.remote_cancel_lease("si1", self.cancel_secret(secret+3))
-        # slot should still be there
+        # the slot should still be there
         shares3 = ss.remote_get_mutable_slot("si1")
         self.failUnlessEqual(len(shares3), 3)
+        self.failUnlessEqual(len(s0.debug_enumerate_leases()), 1)
+
         ss.remote_cancel_lease("si1", self.cancel_secret(secret+4))
         # now the slot should be gone
         self.failUnlessEqual(ss.remote_get_mutable_slot("si1"), {})