Skip to content
Snippets Groups Projects
Commit 04d0da75 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Consistently use `self.clock` so less synchronization is required

parent ec2c31a9
Branches
No related tags found
2 merge requests!231Remove `renew_lease` from our storage protocol,!229Set up CI for Tahoe 1.16.x
...@@ -560,6 +560,10 @@ class ShareTests(TestCase): ...@@ -560,6 +560,10 @@ class ShareTests(TestCase):
# Hypothesis might want to try a case where time is further in the # Hypothesis might want to try a case where time is further in the
# past than an earlier case - so we possibly rewind the clock here. # past than an earlier case - so we possibly rewind the clock here.
synchronize_clocks(from_clock=clock, to_clock=self.clock) synchronize_clocks(from_clock=clock, to_clock=self.clock)
# Throw away the Hypothesis-supplied clock now that we've adopted its
# time. This prevents us from accidentally using it instead of
# self.clock later on.
del clock
# anonymous_storage_server uses time.time() before Tahoe-LAFS 1.16, # anonymous_storage_server uses time.time() before Tahoe-LAFS 1.16,
# unfortunately. For Tahoe-LAFS 1.16, AnonymousStorageServer will # unfortunately. For Tahoe-LAFS 1.16, AnonymousStorageServer will
...@@ -567,7 +571,7 @@ class ShareTests(TestCase): ...@@ -567,7 +571,7 @@ class ShareTests(TestCase):
# monkey-patching. # monkey-patching.
# #
# And useFixture does not interact very well with Hypothesis. # And useFixture does not interact very well with Hypothesis.
patch = MonkeyPatch("time.time", clock.seconds) patch = MonkeyPatch("time.time", self.clock.seconds)
try: try:
patch.setUp() patch.setUp()
# Create a share we can toy with. # Create a share we can toy with.
...@@ -592,7 +596,7 @@ class ShareTests(TestCase): ...@@ -592,7 +596,7 @@ class ShareTests(TestCase):
expected = [{ expected = [{
sharenum: ShareStat( sharenum: ShareStat(
size=size, size=size,
lease_expiration=int(clock.seconds() + LEASE_INTERVAL), lease_expiration=int(self.clock.seconds() + LEASE_INTERVAL),
), ),
}] }]
self.assertThat( self.assertThat(
...@@ -790,7 +794,9 @@ class ShareTests(TestCase): ...@@ -790,7 +794,9 @@ class ShareTests(TestCase):
# See the comment in `_stat_shares_immutable_test` for an explanation # See the comment in `_stat_shares_immutable_test` for an explanation
# of clock handling and time.time monkey-patching. # of clock handling and time.time monkey-patching.
synchronize_clocks(from_clock=clock, to_clock=self.clock) synchronize_clocks(from_clock=clock, to_clock=self.clock)
patch = MonkeyPatch("time.time", clock.seconds) del clock
patch = MonkeyPatch("time.time", self.clock.seconds)
try: try:
patch.setUp() patch.setUp()
# Create a share we can toy with. # Create a share we can toy with.
...@@ -820,7 +826,7 @@ class ShareTests(TestCase): ...@@ -820,7 +826,7 @@ class ShareTests(TestCase):
vectors.write_vector, vectors.write_vector,
vectors.new_length, vectors.new_length,
), ),
lease_expiration=int(clock.seconds() + LEASE_INTERVAL), lease_expiration=int(self.clock.seconds() + LEASE_INTERVAL),
) )
for (sharenum, vectors) for (sharenum, vectors)
in test_and_write_vectors_for_shares.items() in test_and_write_vectors_for_shares.items()
...@@ -1014,6 +1020,11 @@ class ShareTests(TestCase): ...@@ -1014,6 +1020,11 @@ class ShareTests(TestCase):
# up between iterations. # up between iterations.
cleanup_storage_server(self.anonymous_storage_server) cleanup_storage_server(self.anonymous_storage_server)
# See the comment in `_stat_shares_immutable_test` for an explanation
# of clock handling and time.time monkey-patching.
synchronize_clocks(from_clock=clock, to_clock=self.clock)
del clock
secrets = (write_enabler, renew_secret, cancel_secret) secrets = (write_enabler, renew_secret, cancel_secret)
def write(): def write():
...@@ -1028,10 +1039,7 @@ class ShareTests(TestCase): ...@@ -1028,10 +1039,7 @@ class ShareTests(TestCase):
r_vector=[], r_vector=[],
) )
# See the comment in `_stat_shares_immutable_test` for an explanation patch = MonkeyPatch("time.time", self.clock.seconds)
# of clock handling and time.time monkey-patching.
synchronize_clocks(from_clock=clock, to_clock=self.clock)
patch = MonkeyPatch("time.time", clock.seconds)
try: try:
patch.setUp() patch.setUp()
...@@ -1040,12 +1048,7 @@ class ShareTests(TestCase): ...@@ -1040,12 +1048,7 @@ class ShareTests(TestCase):
# Advance time by more than a lease period so the lease is no # Advance time by more than a lease period so the lease is no
# longer valid. # longer valid.
clock.advance(self.server.LEASE_PERIOD.total_seconds() + 1) self.clock.advance(self.server.LEASE_PERIOD.total_seconds() + 1)
# Since we just changed the Hypothesis-supplied clock we need to
# update the other clock (the one StorageServer is looking at)
# too. :/
synchronize_clocks(from_clock=clock, to_clock=self.clock)
self.assertThat(write(), is_successful_write()) self.assertThat(write(), is_successful_write())
finally: finally:
...@@ -1061,7 +1064,7 @@ class ShareTests(TestCase): ...@@ -1061,7 +1064,7 @@ class ShareTests(TestCase):
test_and_write_vectors_for_shares[num].write_vector, test_and_write_vectors_for_shares[num].write_vector,
test_and_write_vectors_for_shares[num].new_length, test_and_write_vectors_for_shares[num].new_length,
), ),
lease_expiration=int(clock.seconds() + self.server.LEASE_PERIOD.total_seconds()), lease_expiration=int(self.clock.seconds() + self.server.LEASE_PERIOD.total_seconds()),
) )
for num for num
in test_and_write_vectors_for_shares in test_and_write_vectors_for_shares
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment