Test another lease edge case.

This commit is contained in:
Itamar Turner-Trauring 2022-05-11 11:50:01 -04:00
parent 17fc9d0064
commit 821bac3ddf
2 changed files with 27 additions and 4 deletions

View File

@ -76,6 +76,7 @@ from allmydata.util.observer import ObserverList
from allmydata.util.rrefutil import add_version_to_remote_reference
from allmydata.util.hashutil import permute_server_hash
from allmydata.util.dictutil import BytesKeyDict, UnicodeKeyDict
from allmydata.util.deferredutil import async_to_deferred
from allmydata.storage.http_client import (
StorageClient, StorageClientImmutables, StorageClientGeneral,
ClientException as HTTPClientException, StorageClientMutables,
@ -1166,16 +1167,23 @@ class _HTTPStorageServer(object):
for share_num in share_numbers
})
def add_lease(
@async_to_deferred
async def add_lease(
self,
storage_index,
renew_secret,
cancel_secret
):
immutable_client = StorageClientImmutables(self._http_client)
return immutable_client.add_or_renew_lease(
storage_index, renew_secret, cancel_secret
)
try:
await immutable_client.add_or_renew_lease(
storage_index, renew_secret, cancel_secret
)
except ClientException as e:
if e.code == http.NOT_FOUND:
# Silently do nothing, as is the case for the Foolscap client
return
raise
def advise_corrupt_share(
self,

View File

@ -459,6 +459,21 @@ class IStorageServerImmutableAPIsTestsMixin(object):
lease.get_expiration_time() - self.fake_time() > (31 * 24 * 60 * 60 - 10)
)
@inlineCallbacks
def test_add_lease_non_existent(self):
"""
If the storage index doesn't exist, adding the lease silently does nothing.
"""
storage_index = new_storage_index()
self.assertEqual(list(self.server.get_leases(storage_index)), [])
renew_secret = new_secret()
cancel_secret = new_secret()
# Add a lease:
yield self.storage_client.add_lease(storage_index, renew_secret, cancel_secret)
self.assertEqual(list(self.server.get_leases(storage_index)), [])
@inlineCallbacks
def test_add_lease_renewal(self):
"""