Skip to content

Commit 1ddd641

Browse files
committed
Add basic rediscluster tests
1 parent ef44b2b commit 1ddd641

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pytest
2+
3+
pytest.importorskip("rediscluster")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pytest
2+
from sentry_sdk import capture_message
3+
import sentry_sdk.integrations
4+
from sentry_sdk.integrations.redis import RedisIntegration
5+
6+
import rediscluster
7+
8+
rediscluster_classes = ["RedisCluster"]
9+
10+
if hasattr(rediscluster, "StrictRedisCluster"):
11+
rediscluster_classes.append("StrictRedisCluster")
12+
13+
14+
@pytest.mark.parametrize("clsname", rediscluster_classes)
15+
def test_rediscluster_basic(clsname, sentry_init, capture_events, monkeypatch):
16+
17+
redis_cluster_cls = getattr(rediscluster, clsname)
18+
19+
execute_command_calls = []
20+
21+
def execute_command(*args, **kwargs):
22+
execute_command_calls.append((args, kwargs))
23+
24+
monkeypatch.setattr(
25+
redis_cluster_cls, "execute_command", execute_command,
26+
)
27+
28+
# should be done by the sentry_init fixture?
29+
sentry_sdk.integrations._installed_integrations = set()
30+
31+
sentry_init(integrations=[RedisIntegration()])
32+
events = capture_events()
33+
34+
rc = redis_cluster_cls(connection_pool=True)
35+
rc.get("foobar")
36+
capture_message("hi")
37+
38+
(event,) = events
39+
(crumb,) = event["breadcrumbs"]
40+
41+
assert crumb == {
42+
"category": "redis",
43+
"message": "GET 'foobar'",
44+
"data": {"redis.key": "foobar", "redis.command": "GET"},
45+
"timestamp": crumb["timestamp"],
46+
"type": "redis",
47+
}

tox.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ envlist =
6262
{py2.7,py3.8}-requests
6363

6464
{py2.7,py3.7,py3.8}-redis
65+
{py2.7,py3.7,py3.8}-rediscluster-{1,2}
6566

6667
py{3.7,3.8}-asgi
6768

@@ -166,8 +167,9 @@ deps =
166167
trytond-4.6: trytond>=4.6,<4.7
167168

168169
redis: fakeredis
169-
# https://github.com/jamesls/fakeredis/issues/245
170-
redis: redis<3.2.2
170+
171+
rediscluster-1: redis-py-cluster>=1.0.0,<2.0.0
172+
rediscluster-2: redis-py-cluster>=2.0.0,<3.0.0
171173

172174
asgi: starlette
173175
asgi: requests
@@ -199,6 +201,7 @@ setenv =
199201
tornado: TESTPATH=tests/integrations/tornado
200202
trytond: TESTPATH=tests/integrations/trytond
201203
redis: TESTPATH=tests/integrations/redis
204+
rediscluster: TESTPATH=tests/integrations/rediscluster
202205
asgi: TESTPATH=tests/integrations/asgi
203206
sqlalchemy: TESTPATH=tests/integrations/sqlalchemy
204207
spark: TESTPATH=tests/integrations/spark

0 commit comments

Comments
 (0)