mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
Start on allocate_bucket tests.
This commit is contained in:
parent
855d02bef0
commit
3bec2a480f
@ -6,13 +6,68 @@ reused across tests, so each test should be careful to generate unique storage
|
|||||||
indexes.
|
indexes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from future.utils import PY2
|
||||||
|
|
||||||
|
if PY2:
|
||||||
|
from future.builtins import (
|
||||||
|
filter,
|
||||||
|
map,
|
||||||
|
zip,
|
||||||
|
ascii,
|
||||||
|
chr,
|
||||||
|
hex,
|
||||||
|
input,
|
||||||
|
next,
|
||||||
|
oct,
|
||||||
|
open,
|
||||||
|
pow,
|
||||||
|
round,
|
||||||
|
super,
|
||||||
|
bytes,
|
||||||
|
dict,
|
||||||
|
list,
|
||||||
|
object,
|
||||||
|
range,
|
||||||
|
str,
|
||||||
|
max,
|
||||||
|
min,
|
||||||
|
) # noqa: F401
|
||||||
|
|
||||||
|
from random import randrange
|
||||||
|
from unittest import expectedFailure
|
||||||
|
|
||||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||||
from twisted.trial.unittest import TestCase
|
from twisted.trial.unittest import TestCase
|
||||||
|
|
||||||
from allmydata.interfaces import IStorageServer
|
from foolscap.api import Referenceable
|
||||||
|
|
||||||
|
from allmydata.interfaces import IStorageServer, RIBucketWriter
|
||||||
from .test_system import SystemTestMixin
|
from .test_system import SystemTestMixin
|
||||||
|
|
||||||
|
|
||||||
|
def _randbytes(length):
|
||||||
|
# type: (int) -> bytes
|
||||||
|
"""Return random bytes string of given length."""
|
||||||
|
return bytes([randrange(0, 256) for _ in range(length)])
|
||||||
|
|
||||||
|
|
||||||
|
def new_storage_index():
|
||||||
|
# type: () -> bytes
|
||||||
|
"""Return a new random storage index."""
|
||||||
|
return _randbytes(16)
|
||||||
|
|
||||||
|
|
||||||
|
def new_secret():
|
||||||
|
# type: () -> bytes
|
||||||
|
"""Return a new random secret (for lease renewal or cancellation)."""
|
||||||
|
return _randbytes(32)
|
||||||
|
|
||||||
|
|
||||||
class IStorageServerSharedAPIsTestsMixin(object):
|
class IStorageServerSharedAPIsTestsMixin(object):
|
||||||
"""
|
"""
|
||||||
Tests for ``IStorageServer``'s shared APIs.
|
Tests for ``IStorageServer``'s shared APIs.
|
||||||
@ -35,13 +90,104 @@ class IStorageServerImmutableAPIsTestsMixin(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO === allocate_buckets + RIBucketWriter ===
|
# TODO === allocate_buckets + RIBucketWriter ===
|
||||||
# TODO allocate_buckets on a new storage index
|
# DONE allocate_buckets on a new storage index
|
||||||
# TODO allocate_buckets on existing bucket with same sharenums
|
# PROG allocate_buckets on existing bucket with same sharenums
|
||||||
# TODO allocate_buckets with smaller sharenums
|
# TODO allocate_buckets with smaller sharenums
|
||||||
# TODO allocate_buckets with larger sharenums
|
# TODO allocate_buckets with larger sharenums
|
||||||
# TODO writes to bucket can happen in any order (write then read)
|
# TODO writes to bucket can happen in any order (write then read)
|
||||||
# TODO overlapping writes ignore already-written data (write then read)
|
# TODO overlapping writes ignore already-written data (write then read)
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
|
def test_allocate_buckets_new(self):
|
||||||
|
"""
|
||||||
|
allocate_buckets() with a new storage index returns the matching
|
||||||
|
shares.
|
||||||
|
"""
|
||||||
|
(already_got, allocated) = yield self.storage_server.allocate_buckets(
|
||||||
|
new_storage_index(),
|
||||||
|
new_secret(),
|
||||||
|
new_secret(),
|
||||||
|
set(range(5)),
|
||||||
|
1024,
|
||||||
|
Referenceable(),
|
||||||
|
)
|
||||||
|
self.assertEqual(already_got, set())
|
||||||
|
self.assertEqual(allocated.keys(), set(range(5)))
|
||||||
|
# We validate the bucket objects' interface in a later test.
|
||||||
|
|
||||||
|
@inlineCallbacks
|
||||||
|
def test_allocate_buckets_repeat(self):
|
||||||
|
"""
|
||||||
|
allocate_buckets() with the same storage index returns the same result,
|
||||||
|
because the shares have not been written to.
|
||||||
|
|
||||||
|
This fails due to https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3793
|
||||||
|
"""
|
||||||
|
si, renew_secret, cancel_secret = (
|
||||||
|
new_storage_index(),
|
||||||
|
new_secret(),
|
||||||
|
new_secret(),
|
||||||
|
)
|
||||||
|
(already_got, allocated) = yield self.storage_server.allocate_buckets(
|
||||||
|
si,
|
||||||
|
renew_secret,
|
||||||
|
cancel_secret,
|
||||||
|
set(range(5)),
|
||||||
|
1024,
|
||||||
|
Referenceable(),
|
||||||
|
)
|
||||||
|
(already_got2, allocated2) = yield self.storage_server.allocate_buckets(
|
||||||
|
si,
|
||||||
|
renew_secret,
|
||||||
|
cancel_secret,
|
||||||
|
set(range(5)),
|
||||||
|
1024,
|
||||||
|
Referenceable(),
|
||||||
|
)
|
||||||
|
self.assertEqual(already_got, already_got2)
|
||||||
|
self.assertEqual(allocated.keys(), allocated2.keys())
|
||||||
|
|
||||||
|
test_allocate_buckets_repeat.todo = (
|
||||||
|
"https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3793"
|
||||||
|
)
|
||||||
|
|
||||||
|
@expectedFailure
|
||||||
|
@inlineCallbacks
|
||||||
|
def test_allocate_buckets_more_sharenums(self):
|
||||||
|
"""
|
||||||
|
allocate_buckets() with the same storage index but more sharenums
|
||||||
|
acknowledges the extra shares don't exist.
|
||||||
|
|
||||||
|
Fails due to https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3793
|
||||||
|
"""
|
||||||
|
si, renew_secret, cancel_secret = (
|
||||||
|
new_storage_index(),
|
||||||
|
new_secret(),
|
||||||
|
new_secret(),
|
||||||
|
)
|
||||||
|
yield self.storage_server.allocate_buckets(
|
||||||
|
si,
|
||||||
|
renew_secret,
|
||||||
|
cancel_secret,
|
||||||
|
set(range(5)),
|
||||||
|
1024,
|
||||||
|
Referenceable(),
|
||||||
|
)
|
||||||
|
(already_got2, allocated2) = yield self.storage_server.allocate_buckets(
|
||||||
|
si,
|
||||||
|
renew_secret,
|
||||||
|
cancel_secret,
|
||||||
|
set(range(7)),
|
||||||
|
1024,
|
||||||
|
Referenceable(),
|
||||||
|
)
|
||||||
|
self.assertEqual(already_got2, set()) # none were fully written
|
||||||
|
self.assertEqual(allocated2.keys(), set(range(7)))
|
||||||
|
|
||||||
|
test_allocate_buckets_more_sharenums.todo = (
|
||||||
|
"https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3793"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class _FoolscapMixin(SystemTestMixin):
|
class _FoolscapMixin(SystemTestMixin):
|
||||||
"""Run tests on Foolscap version of ``IStorageServer."""
|
"""Run tests on Foolscap version of ``IStorageServer."""
|
||||||
|
Loading…
Reference in New Issue
Block a user