Skip to content

Commit

Permalink
Add basic rediscluster tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beezz committed Jul 1, 2020
1 parent ef44b2b commit 0058c31
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tests/integrations/rediscluster/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytest

pytest.importorskip("rediscluster")
38 changes: 38 additions & 0 deletions tests/integrations/rediscluster/test_rediscluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from sentry_sdk import capture_message
import sentry_sdk.integrations
from sentry_sdk.integrations.redis import RedisIntegration

import rediscluster

rediscluster_classes = [rediscluster.RedisCluster]

if hasattr(rediscluster, "StrictRedisCluster"):
rediscluster_classes.append(rediscluster.StrictRedisCluster)


@pytest.fixture(scope="module", autouse=True)
def monkeypatch_rediscluster_classes():
for cls in rediscluster_classes:
cls.execute_command = lambda *_, **__: None


@pytest.mark.parametrize("rediscluster_cls", rediscluster_classes)
def test_rediscluster_basic(rediscluster_cls, sentry_init, capture_events):
sentry_init(integrations=[RedisIntegration()])
events = capture_events()

rc = rediscluster_cls(connection_pool=True)
rc.get("foobar")
capture_message("hi")

(event,) = events
(crumb,) = event["breadcrumbs"]

assert crumb == {
"category": "redis",
"message": "GET 'foobar'",
"data": {"redis.key": "foobar", "redis.command": "GET"},
"timestamp": crumb["timestamp"],
"type": "redis",
}
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ envlist =
{py2.7,py3.8}-requests

{py2.7,py3.7,py3.8}-redis
{py2.7,py3.7,py3.8}-rediscluster-{1,2}

py{3.7,3.8}-asgi

Expand Down Expand Up @@ -166,8 +167,9 @@ deps =
trytond-4.6: trytond>=4.6,<4.7

redis: fakeredis
# https://github.com/jamesls/fakeredis/issues/245
redis: redis<3.2.2

rediscluster-1: redis-py-cluster>=1.0.0,<2.0.0
rediscluster-2: redis-py-cluster>=2.0.0,<3.0.0

asgi: starlette
asgi: requests
Expand Down Expand Up @@ -199,6 +201,7 @@ setenv =
tornado: TESTPATH=tests/integrations/tornado
trytond: TESTPATH=tests/integrations/trytond
redis: TESTPATH=tests/integrations/redis
rediscluster: TESTPATH=tests/integrations/rediscluster
asgi: TESTPATH=tests/integrations/asgi
sqlalchemy: TESTPATH=tests/integrations/sqlalchemy
spark: TESTPATH=tests/integrations/spark
Expand Down

0 comments on commit 0058c31

Please sign in to comment.