More tests.

This commit is contained in:
Itamar Turner-Trauring 2021-09-08 13:52:34 -04:00
parent 3bec2a480f
commit c1b1ed0dc3

View File

@ -89,14 +89,6 @@ class IStorageServerImmutableAPIsTestsMixin(object):
``self.storage_server`` is expected to provide ``IStorageServer``.
"""
# TODO === allocate_buckets + RIBucketWriter ===
# DONE allocate_buckets on a new storage index
# PROG allocate_buckets on existing bucket with same sharenums
# TODO allocate_buckets with smaller sharenums
# TODO allocate_buckets with larger sharenums
# TODO writes to bucket can happen in any order (write then read)
# TODO overlapping writes ignore already-written data (write then read)
@inlineCallbacks
def test_allocate_buckets_new(self):
"""
@ -188,6 +180,103 @@ class IStorageServerImmutableAPIsTestsMixin(object):
"https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3793"
)
@inlineCallbacks
def test_written_shares_are_allocated(self):
"""
Shares that are fully written to show up as allocated in result from
``IStoragServer.allocate_buckets()``. Partially-written or empty
shares don't.
"""
si, renew_secret, cancel_secret = (
new_storage_index(),
new_secret(),
new_secret(),
)
(_, allocated) = yield self.storage_server.allocate_buckets(
si,
renew_secret,
cancel_secret,
set(range(5)),
1024,
Referenceable(),
)
# Bucket 1 is fully written in one go.
yield allocated[1].callRemote("write", 0, b"1" * 1024)
yield allocated[1].callRemote("close")
# Bucket 2 is fully written in two steps.
yield allocated[2].callRemote("write", 0, b"1" * 512)
yield allocated[2].callRemote("write", 512, b"2" * 512)
yield allocated[2].callRemote("close")
# Bucket 0 has partial write.
yield allocated[0].callRemote("write", 0, b"1" * 512)
(already_got, _) = yield self.storage_server.allocate_buckets(
si,
renew_secret,
cancel_secret,
set(range(5)),
1024,
Referenceable(),
)
self.assertEqual(already_got, {1, 2})
@inlineCallbacks
def test_written_shares_are_readable(self):
"""
Shares that are fully written to can be read.
1. The result is not affected by the order in which writes
happened, only by their offsets.
2. When overlapping writes happen, the resulting read returns the
earliest written value.
"""
si, renew_secret, cancel_secret = (
new_storage_index(),
new_secret(),
new_secret(),
)
(_, allocated) = yield self.storage_server.allocate_buckets(
si,
renew_secret,
cancel_secret,
set(range(5)),
1024,
Referenceable(),
)
# Bucket 1 is fully written in order
yield allocated[1].callRemote("write", 0, b"1" * 512)
yield allocated[1].callRemote("write", 512, b"2" * 512)
yield allocated[1].callRemote("close")
# Bucket 2 is fully written in reverse.
yield allocated[2].callRemote("write", 512, b"4" * 512)
yield allocated[2].callRemote("write", 0, b"3" * 512)
yield allocated[2].callRemote("close")
# Bucket 3 has an overlapping write.
yield allocated[3].callRemote("write", 0, b"5" * 20)
yield allocated[3].callRemote("write", 0, b"5" * 24)
yield allocated[3].callRemote("write", 24, b"6" * 1000)
yield allocated[3].callRemote("close")
buckets = yield self.storage_server.get_buckets(si)
self.assertEqual(buckets.keys(), {1, 2, 3})
self.assertEqual(
(yield buckets[1].callRemote("read", 0, 1024)), b"1" * 512 + b"2" * 512
)
self.assertEqual(
(yield buckets[2].callRemote("read", 0, 1024)), b"3" * 512 + b"4" * 512
)
self.assertEqual(
(yield buckets[3].callRemote("read", 0, 1024)), b"5" * 24 + b"6" * 1000
)
class _FoolscapMixin(SystemTestMixin):
"""Run tests on Foolscap version of ``IStorageServer."""