From 177a49e79c882603da64d45995f5fd60dce8c852 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Wed, 29 Jul 2020 15:18:13 +0100 Subject: [PATCH] Reduced time.sleep() in cache touch() tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/cache/tests.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 1ef2cc1bc1..2a3bf57354 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -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)