storage.py: improve test coverage even more

This commit is contained in:
Brian Warner 2007-10-31 01:44:01 -07:00
parent 4bd739435f
commit 948e6b34dd
2 changed files with 23 additions and 3 deletions

View File

@ -23,7 +23,7 @@ class DataTooLargeError(Exception):
# storage/shares/$STORAGEINDEX/$SHARENUM
# $SHARENUM matches this regex:
NUM_RE=re.compile("[0-9]*")
NUM_RE=re.compile("^[0-9]+$")
# each share file (in storage/shares/$SI/$SHNUM) contains lease information
# and share data. The share data is accessed by RIBucketWriter.write and
@ -772,7 +772,7 @@ class StorageServer(service.MultiService, Referenceable):
os.unlink(filename)
total_space_freed += filelen
if not remaining_files:
os.rmdir(storagedir)
fileutil.rm_dir(storagedir)
self.consumed -= total_space_freed
if not found_buckets:
raise IndexError("no such lease to cancel")

View File

@ -7,7 +7,7 @@ from foolscap import Referenceable
import time, os.path, stat
import itertools
from allmydata import interfaces
from allmydata.util import fileutil, hashutil
from allmydata.util import fileutil, hashutil, idlib
from allmydata.storage import BucketWriter, BucketReader, \
WriteBucketProxy, ReadBucketProxy, StorageServer
from allmydata.interfaces import BadWriteEnablerError
@ -699,6 +699,14 @@ class MutableServer(unittest.TestCase):
[(0, data),],
new_length=None)
# create a random non-numeric file in the bucket directory, to
# exercise the code that's supposed to ignore those.
bucket_dir = os.path.join(self.workdir("test_leases"),
"shares", idlib.b2a("si1"))
f = open(os.path.join(bucket_dir, "ignore_me.txt"), "w")
f.write("you ought to be ignoring me\n")
f.close()
# re-allocate the slots and use the same secrets, that should update
# the lease
shares2 = self.allocate(ss, "si1", "we1", secret, set([0,1,2]), 100)
@ -731,6 +739,18 @@ class MutableServer(unittest.TestCase):
ss.remote_renew_lease("si1", self.renew_secret(secret+3))
ss.remote_renew_lease("si1", self.renew_secret(secret+4))
# renewing with a bogus token should prompt an error message
# TODO: examine the exception thus raised, make sure the old nodeid
# is present, to provide for share migration
self.failUnlessRaises(IndexError,
ss.remote_renew_lease, "si1",
self.renew_secret(secret+20))
# same for cancelling
self.failUnlessRaises(IndexError,
ss.remote_cancel_lease, "si1",
self.cancel_secret(secret+20))
# now cancel them all
ss.remote_cancel_lease("si1", self.cancel_secret(secret))
ss.remote_cancel_lease("si1", self.cancel_secret(secret+1))