Reduced time.sleep() in cache touch() tests.

There are 8 cache backends to test and each test of touch() takes
~7s → ~56s. This seems excessive and it feels like we should be able
to reduce this significantly. time.sleep() accepts floating point
values and is guaranteed to sleep for at least the number of seconds
specified as of Python 3.5.

We do run the risk that there may be spurious test failures from this,
but that already seemed to be the case anyway.
This commit is contained in:
Nick Pope 2020-07-29 15:18:13 +01:00 committed by Mariusz Felisiak
parent be183fc94f
commit 177a49e79c
1 changed files with 4 additions and 4 deletions

View File

@ -440,15 +440,15 @@ class BaseCacheTests:
def test_touch(self):
# cache.touch() updates the timeout.
cache.set('expire1', 'very quickly', timeout=1)
self.assertIs(cache.touch('expire1', timeout=4), True)
time.sleep(2)
self.assertIs(cache.touch('expire1', timeout=2), True)
time.sleep(1.0)
self.assertIs(cache.has_key('expire1'), True)
time.sleep(3)
time.sleep(1.5)
self.assertIs(cache.has_key('expire1'), False)
# cache.touch() works without the timeout argument.
cache.set('expire1', 'very quickly', timeout=1)
self.assertIs(cache.touch('expire1'), True)
time.sleep(2)
time.sleep(1.5)
self.assertIs(cache.has_key('expire1'), True)
self.assertIs(cache.touch('nonexistent'), False)