diff --git a/src/_zkapauthorizer/tests/test_storage_protocol.py b/src/_zkapauthorizer/tests/test_storage_protocol.py index f9ad02602a1d8a4567b371a7c48463c052489e35..a77dc29266a905226ea7a38c2d9bd13f7fc96072 100644 --- a/src/_zkapauthorizer/tests/test_storage_protocol.py +++ b/src/_zkapauthorizer/tests/test_storage_protocol.py @@ -179,6 +179,12 @@ class ShareTests(TestCase): # iteration. self.clock.advance(-self.clock.seconds()) + # Reset the state of any passes in our pass factory. + self.pass_factory._clear() + + # And clean out any shares that might confuse things. + cleanup_storage_server(self.anonymous_storage_server) + def test_get_version(self): """ Version information about the storage server can be retrieved using @@ -204,10 +210,6 @@ class ShareTests(TestCase): Any passes rejected by the storage server are reported with a ``MorePassesRequired`` exception sent to the client. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - num_passes = required_passes(self.pass_value, [size] * len(sharenums)) # Pick some passes to mess with. @@ -291,13 +293,6 @@ class ShareTests(TestCase): resulting buckets can be read back using *get_buckets* and methods of those resulting buckets. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - - # Oops our pass factory, too. :( - self.pass_factory._clear() - alreadygot, allocated = extract_result( self.client.allocate_buckets( storage_index, @@ -377,13 +372,6 @@ class ShareTests(TestCase): When the remote *allocate_buckets* implementation reports that shares already exist, passes are not spent for those shares. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - - # Oops our pass factory, too. :( - self.pass_factory._clear() - # A helper that only varies on sharenums. def allocate_buckets(sharenums): return self.client.allocate_buckets( @@ -460,10 +448,6 @@ class ShareTests(TestCase): """ A lease can be added to an existing immutable share. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - # Use a different secret so that it's a new lease and not an # implicit renewal. add_lease_secret, renew_lease_secret = renew_secrets @@ -494,10 +478,6 @@ class ShareTests(TestCase): def _stat_shares_immutable_test( self, storage_index, sharenum, size, when, leases, write_shares ): - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - # Lease cancellation is unimplemented in Tahoe so this doesn't matter. cancel_secret = b"" @@ -594,10 +574,6 @@ class ShareTests(TestCase): """ assume(version != 1) - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - sharedir = FilePath(self.anonymous_storage_server.sharedir).preauthChild( # storage_index_to_dir likes to return multiple segments # joined by pathsep @@ -640,10 +616,6 @@ class ShareTests(TestCase): ``stat_shares`` declines to offer a result (by raising ``ValueError``). """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - sharedir = FilePath(self.anonymous_storage_server.sharedir).preauthChild( # storage_index_to_dir likes to return multiple segments # joined by pathsep @@ -740,10 +712,6 @@ class ShareTests(TestCase): Size and lease information about mutable shares can be retrieved from a storage server. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - self.clock.advance(when) patch = MonkeyPatch("time.time", self.clock.seconds) @@ -803,10 +771,6 @@ class ShareTests(TestCase): """ An advisory of corruption in a share can be sent to the server. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - # Create a share we can toy with. write_toy_shares( self.anonymous_storage_server, @@ -848,10 +812,6 @@ class ShareTests(TestCase): Mutable share data written using *slot_testv_and_readv_and_writev* can be read back as-written and without spending any more passes. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - wrote, read = extract_result( self.client.slot_testv_and_readv_and_writev( storage_index, @@ -901,9 +861,6 @@ class ShareTests(TestCase): *slot_testv_and_readv_and_writev* any leases on the corresponding slot remain the same. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) def leases(): return list( @@ -972,10 +929,6 @@ class ShareTests(TestCase): When mutable share data with an expired lease is rewritten using *slot_testv_and_readv_and_writev* a new lease is paid for and granted. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - self.clock.advance(when) secrets = (write_enabler, renew_secret, cancel_secret) diff --git a/src/_zkapauthorizer/tests/test_storage_server.py b/src/_zkapauthorizer/tests/test_storage_server.py index 49a1701a3dc3ddfadbdb8f912549b978e851d5e7..cdff293f8e7cd638f7b4cb3df1263196584061d5 100644 --- a/src/_zkapauthorizer/tests/test_storage_server.py +++ b/src/_zkapauthorizer/tests/test_storage_server.py @@ -165,16 +165,27 @@ class PassValidationTests(TestCase): self.clock, ) + def setup_example(self): + """ + Prepare the TestCase to run one example of one test. + """ + # The storage server accumulates shares through the course of running + # a single example. Since existing state can invalidate assumptions + # made by the tests, get rid of it. + # + # It might be nice to just create a new, empty storage server here + # instead of cleaning up the old one. For now, that's hard because + # Hypothesis and testtools fixtures don't play nicely together in a + # way that allows us to just move everything from `setUp` into this + # method. + cleanup_storage_server(self.anonymous_storage_server) + def test_allocate_buckets_fails_without_enough_passes(self): """ ``remote_allocate_buckets`` fails with ``MorePassesRequired`` if it is passed fewer passes than it requires for the amount of data to be stored. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - required_passes = 2 share_nums = {3, 7} allocated_size = int((required_passes * self.pass_value) / len(share_nums)) @@ -219,10 +230,6 @@ class PassValidationTests(TestCase): initial writes on shares without supplying passes, the operation fails with ``MorePassesRequired``. """ - # Hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - data = b"01234567" offset = 0 sharenum = 0 @@ -272,10 +279,6 @@ class PassValidationTests(TestCase): vector which will increase the storage requirements of that slot share by at least ``self.pass_value``. """ - # hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - tw_vectors = { k: v.for_call() for (k, v) in test_and_write_vectors_for_shares.items() } @@ -401,10 +404,6 @@ class PassValidationTests(TestCase): with a storage index. It should return the ZKAPAuthorizer binding message for the lease-taking operation. """ - # hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - renew_secret, cancel_secret = secrets required_count = required_passes( @@ -510,10 +509,6 @@ class PassValidationTests(TestCase): ``share_sizes`` returns the size of the requested mutable shares in the requested slot. """ - # hypothesis causes our storage server to be used many times. Clean - # up between iterations. - cleanup_storage_server(self.anonymous_storage_server) - tw_vectors = { k: v.for_call() for (k, v) in test_and_write_vectors_for_shares.items() }