Unit test the new storage server backend API.

This commit is contained in:
Itamar Turner-Trauring 2022-05-05 12:04:45 -04:00
parent 06029d2878
commit 2833bec80e
2 changed files with 25 additions and 1 deletions

View File

@ -695,7 +695,6 @@ class StorageServer(service.MultiService):
Raises ``KeyError`` if the storage index is not known.
"""
# TODO unit test
si_dir = storage_index_to_dir(storage_index)
# shares exist if there is a file for them
bucketdir = os.path.join(self.sharedir, si_dir)

View File

@ -1315,6 +1315,31 @@ class MutableServer(unittest.TestCase):
self.failUnless(isinstance(readv_data, dict))
self.failUnlessEqual(len(readv_data), 0)
def test_list_mutable_shares(self):
"""
``StorageServer.list_mutable_shares()`` returns a set of share numbers
for the given storage index, or raises ``KeyError`` if it does not exist at all.
"""
ss = self.create("test_list_mutable_shares")
# Initially, nothing exists:
with self.assertRaises(KeyError):
ss.list_mutable_shares(b"si1")
self.allocate(ss, b"si1", b"we1", b"le1", [0, 1, 4, 2], 12)
shares0_1_2_4 = ss.list_mutable_shares(b"si1")
# Remove share 2, by setting size to 0:
secrets = (self.write_enabler(b"we1"),
self.renew_secret(b"le1"),
self.cancel_secret(b"le1"))
ss.slot_testv_and_readv_and_writev(b"si1", secrets, {2: ([], [], 0)}, [])
shares0_1_4 = ss.list_mutable_shares(b"si1")
self.assertEqual(
(shares0_1_2_4, shares0_1_4),
({0, 1, 2, 4}, {0, 1, 4})
)
def test_bad_magic(self):
ss = self.create("test_bad_magic")
self.allocate(ss, b"si1", b"we1", next(self._lease_secret), set([0]), 10)