diff options
author | Hendrik Muhs <hendrik@cliqz.com> | 2014-12-04 10:04:12 +0100 |
---|---|---|
committer | Hendrik Muhs <hendrik@cliqz.com> | 2014-12-04 10:04:12 +0100 |
commit | e31e98ba66cf3b16fc6a1658b23400102a782f11 (patch) | |
tree | 243cecf8aa11e6c7ff2f73e18393f9886be839f5 /tests/test_scripting.py | |
parent | fa714e08ef59d37b145616cb60939eedafda0bd4 (diff) | |
download | redis-py-e31e98ba66cf3b16fc6a1658b23400102a782f11.tar.gz |
UnicodeDecodeErrorfix unicode encode error when using pipeline in combination with msgpack and lua
Diffstat (limited to 'tests/test_scripting.py')
-rw-r--r-- | tests/test_scripting.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_scripting.py b/tests/test_scripting.py index 4849c81..2e6f549 100644 --- a/tests/test_scripting.py +++ b/tests/test_scripting.py @@ -10,6 +10,16 @@ local value = redis.call('GET', KEYS[1]) value = tonumber(value) return value * ARGV[1]""" +msgpack_hello_script = """ +local message = cmsgpack.unpack(ARGV[1]) +local name = message['name'] +return "hello " .. name +""" +msgpack_hello_script_broken = """ +local message = cmsgpack.unpack(ARGV[1]) +local names = message['name'] +return "hello " .. name +""" class TestScripting(object): @pytest.fixture(autouse=True) @@ -80,3 +90,24 @@ class TestScripting(object): assert r.script_exists(multiply.sha) == [False] # [SET worked, GET 'a', result of multiple script] assert pipe.execute() == [True, b('2'), 6] + + def test_eval_msgpack_pipeline_error_in_lua(self, r): + msgpack_hello = r.register_script(msgpack_hello_script) + assert not msgpack_hello.sha + + pipe = r.pipeline() + + # avoiding a dependency to msgpack, this is the output of msgpack.dumps({"name": "joe"}) + msgpack_message_1 = b'\x81\xa4name\xa3Joe' + + msgpack_hello(args=[msgpack_message_1], client = pipe) + + assert r.script_exists(msgpack_hello.sha) == [True] + assert pipe.execute()[0] == b'hello Joe' + + msgpack_hello_broken = r.register_script(msgpack_hello_script_broken) + + msgpack_hello_broken(args=[msgpack_message_1], client = pipe) + with pytest.raises(exceptions.ResponseError) as excinfo: + pipe.execute() + assert excinfo.type == exceptions.ResponseError
\ No newline at end of file |