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 2406aed
Show file tree
Hide file tree
Showing 3 changed files with 59 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")
51 changes: 51 additions & 0 deletions tests/integrations/rediscluster/test_rediscluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from sentry_sdk import capture_message
import sentry_sdk.integrations
from sentry_sdk.integrations.redis import RedisIntegration

import rediscluster


def _test_rediscluster_basic(sentry_init, capture_events, monkeypatch, clsname):

redis_cluster_cls = getattr(rediscluster, clsname)

execute_command_calls = []

def execute_command(*args, **kwargs):
execute_command_calls.append((args, kwargs))

monkeypatch.setattr(
redis_cluster_cls, "execute_command", execute_command,
)

# should be done by the sentry_init fixture?
sentry_sdk.integrations._installed_integrations = set()

sentry_init(integrations=[RedisIntegration()])
events = capture_events()

rc = redis_cluster_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",
}


def test_rediscluster_basic(sentry_init, capture_events, monkeypatch):
# RedisCluster is present in all versions
_test_rediscluster_basic(sentry_init, capture_events, monkeypatch, "RedisCluster")


def test_astrictrediscluster_basic(sentry_init, capture_events, monkeypatch):
clsname = "StrictRedisCluster"
if hasattr(rediscluster, clsname):
_test_rediscluster_basic(sentry_init, capture_events, monkeypatch, clsname)
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 2406aed

Please sign in to comment.