Skip to content

Commit 0058c31

Browse files
committed
Add basic rediscluster tests
1 parent ef44b2b commit 0058c31

File tree

3 files changed

+46
-2
lines changed

3 files changed

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

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)