diff --git a/src/_zkapauthorizer/tests/fixtures.py b/src/_zkapauthorizer/tests/fixtures.py index 3a4e4155fb8cbf4f19c36bd6f0e29c22b2ad79bc..e017eadd6b42f10f6f4255caf5c110d64cfca7de 100644 --- a/src/_zkapauthorizer/tests/fixtures.py +++ b/src/_zkapauthorizer/tests/fixtures.py @@ -21,7 +21,6 @@ from __future__ import absolute_import from base64 import b64encode import attr -from allmydata import __version__ as allmydata_version from allmydata.storage.server import StorageServer from fixtures import Fixture, TempDir from twisted.internet.task import Clock @@ -51,18 +50,10 @@ class AnonymousStorageServer(Fixture): def _setUp(self): self.tempdir = FilePath(self.useFixture(TempDir()).join(b"storage")) - if allmydata_version >= "1.16.": - # This version of Tahoe adds a new StorageServer argument for - # controlling time. - timeargs = {"get_current_time": self.clock.seconds} - else: - # Older versions just use time.time() and there's not much we can - # do _here_. Code somewhere else will have to monkey-patch that - # to control things. - timeargs = {} - self.storage_server = StorageServer( - self.tempdir.asBytesMode().path, b"x" * 20, **timeargs + self.tempdir.asBytesMode().path, + b"x" * 20, + clock=self.clock, ) diff --git a/src/_zkapauthorizer/tests/test_storage_protocol.py b/src/_zkapauthorizer/tests/test_storage_protocol.py index a5b642997cb07c01ced81c33090f59713ef9f34e..b0af8db4c775c794455299ca4e25b27cdb427152 100644 --- a/src/_zkapauthorizer/tests/test_storage_protocol.py +++ b/src/_zkapauthorizer/tests/test_storage_protocol.py @@ -21,7 +21,6 @@ from __future__ import absolute_import from allmydata.storage.common import storage_index_to_dir from allmydata.storage.shares import get_share_file from challenge_bypass_ristretto import PublicKey, random_signing_key -from fixtures import MonkeyPatch from foolscap.referenceable import LocalReferenceable from hypothesis import assume, given from hypothesis.strategies import data as data_strategy @@ -540,33 +539,22 @@ class ShareTests(TestCase): self.clock.advance(when) - # anonymous_storage_server uses time.time() before Tahoe-LAFS 1.16, - # unfortunately. For Tahoe-LAFS 1.16, AnonymousStorageServer will - # glue self.clock in for us. For older versions we still need this - # monkey-patching. - # - # And useFixture does not interact very well with Hypothesis. - patch = MonkeyPatch("time.time", self.clock.seconds) - try: - patch.setUp() - # Create a share we can toy with. - write_shares( - self.anonymous_storage_server, + # Create a share we can toy with. + write_shares( + self.anonymous_storage_server, + storage_index, + {sharenum}, + size, + canary=self.canary, + ) + # Perhaps put some more leases on it. Leases might impact our + # ability to determine share data size. + for renew_secret in leases: + self.anonymous_storage_server.remote_add_lease( storage_index, - {sharenum}, - size, - canary=self.canary, + renew_secret, + cancel_secret, ) - # Perhaps put some more leases on it. Leases might impact our - # ability to determine share data size. - for renew_secret in leases: - self.anonymous_storage_server.remote_add_lease( - storage_index, - renew_secret, - cancel_secret, - ) - finally: - patch.cleanUp() expected = [ { @@ -771,23 +759,18 @@ class ShareTests(TestCase): """ self.clock.advance(when) - patch = MonkeyPatch("time.time", self.clock.seconds) - try: - patch.setUp() - # Create a share we can toy with. - wrote, read = extract_result( - self.client.slot_testv_and_readv_and_writev( - storage_index, - secrets=secrets, - tw_vectors={ - k: v.for_call() - for (k, v) in test_and_write_vectors_for_shares.items() - }, - r_vector=[], - ), - ) - finally: - patch.cleanUp() + # Create a share we can toy with. + wrote, read = extract_result( + self.client.slot_testv_and_readv_and_writev( + storage_index, + secrets=secrets, + tw_vectors={ + k: v.for_call() + for (k, v) in test_and_write_vectors_for_shares.items() + }, + r_vector=[], + ), + ) self.assertThat( wrote, Equals(True), @@ -1052,20 +1035,14 @@ class ShareTests(TestCase): r_vector=[], ) - patch = MonkeyPatch("time.time", self.clock.seconds) - try: - patch.setUp() - - # Create a share we can toy with. - self.assertThat(write(), is_successful_write()) + # Create a share we can toy with. + self.assertThat(write(), is_successful_write()) - # Advance time by more than a lease period so the lease is no - # longer valid. - self.clock.advance(self.server.LEASE_PERIOD.total_seconds() + 1) + # Advance time by more than a lease period so the lease is no + # longer valid. + self.clock.advance(self.server.LEASE_PERIOD.total_seconds() + 1) - self.assertThat(write(), is_successful_write()) - finally: - patch.cleanUp() + self.assertThat(write(), is_successful_write()) # The spent passes have been reported to the spending service. self.assertThat(