Skip to content

Commit dbdc466

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

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
from sentry_sdk import capture_message
3+
from sentry_sdk.integrations.redis import RedisIntegration
4+
5+
import rediscluster
6+
7+
rediscluster_classes = [rediscluster.RedisCluster]
8+
9+
if hasattr(rediscluster, "StrictRedisCluster"):
10+
rediscluster_classes.append(rediscluster.StrictRedisCluster)
11+
12+
13+
@pytest.fixture(scope="module", autouse=True)
14+
def monkeypatch_rediscluster_classes():
15+
for cls in rediscluster_classes:
16+
cls.execute_command = lambda *_, **__: None
17+
18+
19+
@pytest.mark.parametrize("rediscluster_cls", rediscluster_classes)
20+
def test_rediscluster_basic(rediscluster_cls, sentry_init, capture_events):
21+
sentry_init(integrations=[RedisIntegration()])
22+
events = capture_events()
23+
24+
rc = rediscluster_cls(connection_pool=True)
25+
rc.get("foobar")
26+
capture_message("hi")
27+
28+
(event,) = events
29+
(crumb,) = event["breadcrumbs"]
30+
31+
assert crumb == {
32+
"category": "redis",
33+
"message": "GET 'foobar'",
34+
"data": {"redis.key": "foobar", "redis.command": "GET"},
35+
"timestamp": crumb["timestamp"],
36+
"type": "redis",
37+
}

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)