summaryrefslogtreecommitdiff
path: root/tests/test_scripting.py
diff options
context:
space:
mode:
authorBen Greenberg <bgreenberg@eventbrite.com>2017-06-15 12:07:55 -0700
committerBen Greenberg <bgreenberg@eventbrite.com>2017-06-15 12:07:55 -0700
commit16c8dd5be0ecda4f561c2549accc19c41f4ca154 (patch)
tree031eaaed4071fa1d6d0b6845e500ff8193429171 /tests/test_scripting.py
parent94975d310353a656fb12fd68cdd2f2a4ca5ae502 (diff)
downloadredis-py-16c8dd5be0ecda4f561c2549accc19c41f4ca154.tar.gz
update tests to reflect the fact that the script sha is precalculated
Diffstat (limited to 'tests/test_scripting.py')
-rw-r--r--tests/test_scripting.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/tests/test_scripting.py b/tests/test_scripting.py
index 2213ec6..7d0f585 100644
--- a/tests/test_scripting.py
+++ b/tests/test_scripting.py
@@ -57,44 +57,49 @@ class TestScripting(object):
def test_script_object(self, r):
r.set('a', 2)
multiply = r.register_script(multiply_script)
- assert not multiply.sha
- # test evalsha fail -> script load + retry
+ precalculated_sha = multiply.sha
+ assert precalculated_sha
+ assert r.script_exists(multiply.sha) == [False]
+ # Test second evalsha block (after NoScriptError)
assert multiply(keys=['a'], args=[3]) == 6
- assert multiply.sha
+ # At this point, the script should be loaded
assert r.script_exists(multiply.sha) == [True]
- # test first evalsha
+ # Test that the precalculated sha matches the one from redis
+ assert multiply.sha == precalculated_sha
+ # Test first evalsha block
assert multiply(keys=['a'], args=[3]) == 6
def test_script_object_in_pipeline(self, r):
multiply = r.register_script(multiply_script)
- assert not multiply.sha
+ precalculated_sha = multiply.sha
+ assert precalculated_sha
pipe = r.pipeline()
pipe.set('a', 2)
pipe.get('a')
multiply(keys=['a'], args=[3], client=pipe)
- # even though the pipeline wasn't executed yet, we made sure the
- # script was loaded and got a valid sha
- assert multiply.sha
- assert r.script_exists(multiply.sha) == [True]
+ assert r.script_exists(multiply.sha) == [False]
# [SET worked, GET 'a', result of multiple script]
assert pipe.execute() == [True, b('2'), 6]
+ # The script should have been loaded by pipe.execute()
+ assert r.script_exists(multiply.sha) == [True]
+ # The precalculated sha should have been the correct one
+ assert multiply.sha == precalculated_sha
# purge the script from redis's cache and re-run the pipeline
- # the multiply script object knows it's sha, so it shouldn't get
- # reloaded until pipe.execute()
+ # the multiply script should be reloaded by pipe.execute()
r.script_flush()
pipe = r.pipeline()
pipe.set('a', 2)
pipe.get('a')
- assert multiply.sha
multiply(keys=['a'], args=[3], client=pipe)
assert r.script_exists(multiply.sha) == [False]
# [SET worked, GET 'a', result of multiple script]
assert pipe.execute() == [True, b('2'), 6]
+ assert r.script_exists(multiply.sha) == [True]
def test_eval_msgpack_pipeline_error_in_lua(self, r):
msgpack_hello = r.register_script(msgpack_hello_script)
- assert not msgpack_hello.sha
+ assert msgpack_hello.sha
pipe = r.pipeline()