Skip to content

Commit

Permalink
Merge pull request #1139 from tahoe-lafs/3812-test-advise-corrupt-share
Browse files Browse the repository at this point in the history
Tests for IStorageServer.advise_corrupt_share

Fixes ticket:3812
  • Loading branch information
itamarst committed Oct 18, 2021
2 parents efc9dc8 + e099bc6 commit 4c7e503
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
Empty file added newsfragments/3812.minor
Empty file.
2 changes: 1 addition & 1 deletion src/allmydata/immutable/downloader/share.py
Expand Up @@ -475,7 +475,7 @@ def _signal_corruption(self, f, start, offset):
# there was corruption somewhere in the given range
reason = "corruption in share[%d-%d): %s" % (start, start+offset,
str(f.value))
self._rref.callRemote(
return self._rref.callRemote(
"advise_corrupt_share", reason.encode("utf-8")
).addErrback(log.err, "Error from remote call to advise_corrupt_share")

Expand Down
2 changes: 1 addition & 1 deletion src/allmydata/immutable/layout.py
Expand Up @@ -254,7 +254,7 @@ def close(self):
return d

def abort(self):
self._rref.callRemote("abort").addErrback(log.err, "Error from remote call to abort an immutable write bucket")
return self._rref.callRemote("abort").addErrback(log.err, "Error from remote call to abort an immutable write bucket")

def get_servername(self):
return self._server.get_name()
Expand Down
2 changes: 1 addition & 1 deletion src/allmydata/storage_client.py
Expand Up @@ -1017,7 +1017,7 @@ def advise_corrupt_share(
shnum,
reason,
):
self._rref.callRemote(
return self._rref.callRemote(
"advise_corrupt_share",
share_type,
storage_index,
Expand Down
54 changes: 47 additions & 7 deletions src/allmydata/test/test_istorageserver.py
Expand Up @@ -20,7 +20,7 @@

from random import Random

from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks, returnValue

from foolscap.api import Referenceable, RemoteException

Expand Down Expand Up @@ -405,12 +405,8 @@ def test_read_bucket_at_offset(self):
)

@inlineCallbacks
def test_bucket_advise_corrupt_share(self):
"""
Calling ``advise_corrupt_share()`` on a bucket returned by
``IStorageServer.get_buckets()`` does not result in error (other
behavior is opaque at this level of abstraction).
"""
def create_share(self):
"""Create a share, return the storage index."""
storage_index = new_storage_index()
(_, allocated) = yield self.storage_server.allocate_buckets(
storage_index,
Expand All @@ -423,10 +419,31 @@ def test_bucket_advise_corrupt_share(self):

yield allocated[0].callRemote("write", 0, b"0123456789")
yield allocated[0].callRemote("close")
returnValue(storage_index)

@inlineCallbacks
def test_bucket_advise_corrupt_share(self):
"""
Calling ``advise_corrupt_share()`` on a bucket returned by
``IStorageServer.get_buckets()`` does not result in error (other
behavior is opaque at this level of abstraction).
"""
storage_index = yield self.create_share()
buckets = yield self.storage_server.get_buckets(storage_index)
yield buckets[0].callRemote("advise_corrupt_share", b"OH NO")

@inlineCallbacks
def test_advise_corrupt_share(self):
"""
Calling ``advise_corrupt_share()`` on an immutable share does not
result in error (other behavior is opaque at this level of
abstraction).
"""
storage_index = yield self.create_share()
yield self.storage_server.advise_corrupt_share(
b"immutable", storage_index, 0, b"ono"
)


class IStorageServerMutableAPIsTestsMixin(object):
"""
Expand Down Expand Up @@ -780,6 +797,29 @@ def test_slot_readv_no_shares(self):
{0: [b"abcdefg"], 1: [b"0123456"], 2: [b"9876543"]},
)

@inlineCallbacks
def test_advise_corrupt_share(self):
"""
Calling ``advise_corrupt_share()`` on a mutable share does not
result in error (other behavior is opaque at this level of
abstraction).
"""
secrets = self.new_secrets()
storage_index = new_storage_index()
(written, _) = yield self.staraw(
storage_index,
secrets,
tw_vectors={
0: ([], [(0, b"abcdefg")], 7),
},
r_vector=[],
)
self.assertEqual(written, True)

yield self.storage_server.advise_corrupt_share(
b"mutable", storage_index, 0, b"ono"
)


class _FoolscapMixin(SystemTestMixin):
"""Run tests on Foolscap version of ``IStorageServer."""
Expand Down

0 comments on commit 4c7e503

Please sign in to comment.