Skip to content

Commit 747561d

Browse files
committed
Add basic rediscluster tests
1 parent e4c36e2 commit 747561d

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

tests/integrations/rediscluster/__init__.py

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

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)