From: Brian Warner Date: Wed, 31 Oct 2007 19:07:47 +0000 (-0700) Subject: storage.py: more test coverage, make sure leases survive resizing X-Git-Tag: allmydata-tahoe-0.7.0~336 X-Git-Url: https://git.rkrishnan.org/pf/content/en/footer/(%5B%5E?a=commitdiff_plain;h=70e7961088ec6b5faf37d2f42f41b15556494f33;p=tahoe-lafs%2Ftahoe-lafs.git storage.py: more test coverage, make sure leases survive resizing --- diff --git a/src/allmydata/storage.py b/src/allmydata/storage.py index f8caa72f..2ae8521c 100644 --- a/src/allmydata/storage.py +++ b/src/allmydata/storage.py @@ -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) diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index bc2258ae..27b39e6e 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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"), {})