Skip to content

Commit ffa35f0

Browse files
committed
Add unit tests
1 parent d267aa4 commit ffa35f0

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

tests/test_cluster.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,23 +1692,23 @@ def test_cluster_bitop_not_empty_string(self, r):
16921692

16931693
@skip_if_server_version_lt("2.6.0")
16941694
def test_cluster_bitop_not(self, r):
1695-
test_str = b"\xAA\x00\xFF\x55"
1695+
test_str = b"\xaa\x00\xff\x55"
16961696
correct = ~0xAA00FF55 & 0xFFFFFFFF
16971697
r["{foo}a"] = test_str
16981698
r.bitop("not", "{foo}r", "{foo}a")
16991699
assert int(binascii.hexlify(r["{foo}r"]), 16) == correct
17001700

17011701
@skip_if_server_version_lt("2.6.0")
17021702
def test_cluster_bitop_not_in_place(self, r):
1703-
test_str = b"\xAA\x00\xFF\x55"
1703+
test_str = b"\xaa\x00\xff\x55"
17041704
correct = ~0xAA00FF55 & 0xFFFFFFFF
17051705
r["{foo}a"] = test_str
17061706
r.bitop("not", "{foo}a", "{foo}a")
17071707
assert int(binascii.hexlify(r["{foo}a"]), 16) == correct
17081708

17091709
@skip_if_server_version_lt("2.6.0")
17101710
def test_cluster_bitop_single_string(self, r):
1711-
test_str = b"\x01\x02\xFF"
1711+
test_str = b"\x01\x02\xff"
17121712
r["{foo}a"] = test_str
17131713
r.bitop("and", "{foo}res1", "{foo}a")
17141714
r.bitop("or", "{foo}res2", "{foo}a")
@@ -1719,8 +1719,8 @@ def test_cluster_bitop_single_string(self, r):
17191719

17201720
@skip_if_server_version_lt("2.6.0")
17211721
def test_cluster_bitop_string_operands(self, r):
1722-
r["{foo}a"] = b"\x01\x02\xFF\xFF"
1723-
r["{foo}b"] = b"\x01\x02\xFF"
1722+
r["{foo}a"] = b"\x01\x02\xff\xff"
1723+
r["{foo}b"] = b"\x01\x02\xff"
17241724
r.bitop("and", "{foo}res1", "{foo}a", "{foo}b")
17251725
r.bitop("or", "{foo}res2", "{foo}a", "{foo}b")
17261726
r.bitop("xor", "{foo}res3", "{foo}a", "{foo}b")
@@ -3260,6 +3260,27 @@ def raise_ask_error():
32603260
assert ask_node.redis_connection.connection.read_response.called
32613261
assert res == ["MOCK_OK"]
32623262

3263+
def test_error_is_truncated(self, r):
3264+
"""
3265+
Test that an error from the pipeline is truncated correctly.
3266+
"""
3267+
key = "a" * 5000
3268+
3269+
pipe = r.pipeline(transaction=False)
3270+
3271+
with r.pipeline() as pipe:
3272+
pipe.set(key, 1)
3273+
pipe.llen(key)
3274+
pipe.expire(key, 100)
3275+
3276+
with pytest.raises(Exception) as ex:
3277+
pipe.execute()
3278+
3279+
expected = (
3280+
"Command # 2 (LLEN " + ("a" * 95) + "...) of pipeline caused error: "
3281+
)
3282+
assert str(ex.value).startswith(expected)
3283+
32633284
def test_return_previously_acquired_connections(self, r):
32643285
# in order to ensure that a pipeline will make use of connections
32653286
# from different nodes

tests/test_pipeline.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,22 @@ def test_exec_error_in_no_transaction_pipeline_unicode_command(self, r):
369369

370370
assert r[key] == b"1"
371371

372+
@pytest.mark.onlynoncluster
373+
def test_exec_error_in_pipeline_truncated(self, r):
374+
key = "a" * 5000
375+
r[key] = 1
376+
with r.pipeline() as pipe:
377+
pipe.llen(key)
378+
pipe.expire(key, 100)
379+
380+
with pytest.raises(redis.ResponseError) as ex:
381+
pipe.execute()
382+
383+
expected = (
384+
"Command # 1 (LLEN " + ("a" * 95) + "...) of pipeline caused error: "
385+
)
386+
assert str(ex.value).startswith(expected)
387+
372388
def test_pipeline_with_bitfield(self, r):
373389
with r.pipeline() as pipe:
374390
pipe.set("a", "1")

0 commit comments

Comments
 (0)