summaryrefslogtreecommitdiff
path: root/tests/test_lock.py
diff options
context:
space:
mode:
authorlaixintao <laixintaoo@gmail.com>2020-03-10 11:18:33 +0800
committerAndy McCurdy <andy@andymccurdy.com>2020-03-24 14:56:15 -0700
commitd1279291d68c77709d69fe13aa7ff6d912d98ce4 (patch)
tree8a577af44668d63f31dbdeae3a7282fb735bba4e /tests/test_lock.py
parentf2f470e192f3ddff66d79293c85e06e7e910316f (diff)
downloadredis-py-d1279291d68c77709d69fe13aa7ff6d912d98ce4.tar.gz
Lock.extend() can now replace the lock's existing TTL with a new value
Lock.extend() now has a new option, `replace_ttl`. When False (the default), Lock.extend() adds the `additional_time` to the lock's existing TTL. When replace_ttl=True, the lock's existing TTL is replaced with the value of `additional_time`.
Diffstat (limited to 'tests/test_lock.py')
-rw-r--r--tests/test_lock.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/test_lock.py b/tests/test_lock.py
index 8b2cc5b..efa9184 100644
--- a/tests/test_lock.py
+++ b/tests/test_lock.py
@@ -149,6 +149,14 @@ class TestLock(object):
assert 16000 < r.pttl('foo') <= 20000
lock.release()
+ def test_extend_lock_replace_ttl(self, r):
+ lock = self.get_lock(r, 'foo', timeout=10)
+ assert lock.acquire(blocking=False)
+ assert 8000 < r.pttl('foo') <= 10000
+ assert lock.extend(10, replace_ttl=True)
+ assert 8000 < r.pttl('foo') <= 10000
+ lock.release()
+
def test_extend_lock_float(self, r):
lock = self.get_lock(r, 'foo', timeout=10.0)
assert lock.acquire(blocking=False)