apply the MutableShareFile tests to all known schemas

This commit is contained in:
Jean-Paul Calderone 2021-11-04 15:37:29 -04:00
parent 931ddf85a5
commit 728638fe23

View File

@ -42,9 +42,12 @@ from allmydata.util import fileutil, hashutil, base32
from allmydata.storage.server import StorageServer, DEFAULT_RENEWAL_TIME from allmydata.storage.server import StorageServer, DEFAULT_RENEWAL_TIME
from allmydata.storage.shares import get_share_file from allmydata.storage.shares import get_share_file
from allmydata.storage.mutable import MutableShareFile from allmydata.storage.mutable import MutableShareFile
from allmydata.storage.mutable_schema import (
ALL_SCHEMAS as ALL_MUTABLE_SCHEMAS,
)
from allmydata.storage.immutable import BucketWriter, BucketReader, ShareFile from allmydata.storage.immutable import BucketWriter, BucketReader, ShareFile
from allmydata.storage.immutable_schema import ( from allmydata.storage.immutable_schema import (
ALL_SCHEMAS, ALL_SCHEMAS as ALL_IMMUTABLE_SCHEMAS,
) )
from allmydata.storage.common import storage_index_to_dir, \ from allmydata.storage.common import storage_index_to_dir, \
UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError, \ UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError, \
@ -3131,7 +3134,7 @@ class Stats(unittest.TestCase):
self.failUnless(output["get"]["99_0_percentile"] is None, output) self.failUnless(output["get"]["99_0_percentile"] is None, output)
self.failUnless(output["get"]["99_9_percentile"] is None, output) self.failUnless(output["get"]["99_9_percentile"] is None, output)
immutable_schemas = strategies.sampled_from(list(ALL_SCHEMAS)) immutable_schemas = strategies.sampled_from(list(ALL_IMMUTABLE_SCHEMAS))
class ShareFileTests(unittest.TestCase): class ShareFileTests(unittest.TestCase):
"""Tests for allmydata.storage.immutable.ShareFile.""" """Tests for allmydata.storage.immutable.ShareFile."""
@ -3270,15 +3273,17 @@ class ShareFileTests(unittest.TestCase):
(loaded_lease,) = sf.get_leases() (loaded_lease,) = sf.get_leases()
self.assertTrue(loaded_lease.is_cancel_secret(cancel_secret)) self.assertTrue(loaded_lease.is_cancel_secret(cancel_secret))
mutable_schemas = strategies.sampled_from(list(ALL_MUTABLE_SCHEMAS))
class MutableShareFileTests(unittest.TestCase): class MutableShareFileTests(unittest.TestCase):
""" """
Tests for allmydata.storage.mutable.MutableShareFile. Tests for allmydata.storage.mutable.MutableShareFile.
""" """
def get_sharefile(self): def get_sharefile(self, **kwargs):
return MutableShareFile(self.mktemp()) return MutableShareFile(self.mktemp(), **kwargs)
@given( @given(
schema=mutable_schemas,
nodeid=strategies.just(b"x" * 20), nodeid=strategies.just(b"x" * 20),
write_enabler=strategies.just(b"y" * 32), write_enabler=strategies.just(b"y" * 32),
datav=strategies.lists( datav=strategies.lists(
@ -3289,12 +3294,12 @@ class MutableShareFileTests(unittest.TestCase):
), ),
new_length=offsets(), new_length=offsets(),
) )
def test_readv_reads_share_data(self, nodeid, write_enabler, datav, new_length): def test_readv_reads_share_data(self, schema, nodeid, write_enabler, datav, new_length):
""" """
``MutableShareFile.readv`` returns bytes from the share data portion ``MutableShareFile.readv`` returns bytes from the share data portion
of the share file. of the share file.
""" """
sf = self.get_sharefile() sf = self.get_sharefile(schema=schema)
sf.create(my_nodeid=nodeid, write_enabler=write_enabler) sf.create(my_nodeid=nodeid, write_enabler=write_enabler)
sf.writev(datav=datav, new_length=new_length) sf.writev(datav=datav, new_length=new_length)
@ -3329,12 +3334,13 @@ class MutableShareFileTests(unittest.TestCase):
self.assertEqual(expected_data, read_data) self.assertEqual(expected_data, read_data)
@given( @given(
schema=mutable_schemas,
nodeid=strategies.just(b"x" * 20), nodeid=strategies.just(b"x" * 20),
write_enabler=strategies.just(b"y" * 32), write_enabler=strategies.just(b"y" * 32),
readv=strategies.lists(strategies.tuples(offsets(), lengths()), min_size=1), readv=strategies.lists(strategies.tuples(offsets(), lengths()), min_size=1),
random=strategies.randoms(), random=strategies.randoms(),
) )
def test_readv_rejects_negative_length(self, nodeid, write_enabler, readv, random): def test_readv_rejects_negative_length(self, schema, nodeid, write_enabler, readv, random):
""" """
If a negative length is given to ``MutableShareFile.readv`` in a read If a negative length is given to ``MutableShareFile.readv`` in a read
vector then ``AssertionError`` is raised. vector then ``AssertionError`` is raised.
@ -3373,7 +3379,7 @@ class MutableShareFileTests(unittest.TestCase):
*broken_readv[readv_index] *broken_readv[readv_index]
) )
sf = self.get_sharefile() sf = self.get_sharefile(schema=schema)
sf.create(my_nodeid=nodeid, write_enabler=write_enabler) sf.create(my_nodeid=nodeid, write_enabler=write_enabler)
# A read with a broken read vector is an error. # A read with a broken read vector is an error.