Skip to content

Commit e7c8b64

Browse files
author
ds
committed
test(relay): Add tests for redis-sentinel support
1 parent 5e8dfc2 commit e7c8b64

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Bring up Redis Sentinel Cluster
2+
description: >-
3+
Installs docker-compose and runs Redis Sentinel cluster
4+
with ports 16379-16380 for redis and
5+
26379-26380 for sentinel
6+
runs:
7+
using: composite
8+
steps:
9+
- name: Set up Docker Compose
10+
uses: docker/setup-compose-action@364cc21a5de5b1ee4a7f5f9d3fa374ce0ccde746
11+
12+
- name: Run Sentinel cluster
13+
env:
14+
ACTION_PATH: ${{ github.action_path }}
15+
shell: bash
16+
run: |
17+
docker compose --file "${ACTION_PATH}/docker-compose.yml" up --detach
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
services:
2+
redis-master:
3+
image: ghcr.io/getsentry/image-mirror-library-redis:5.0-alpine
4+
container_name: redis-master
5+
command:
6+
- redis-server
7+
- --port
8+
- "16379"
9+
ports:
10+
- "16379:16379"
11+
networks:
12+
- sentinel-cluster
13+
14+
redis-replica:
15+
image: ghcr.io/getsentry/image-mirror-library-redis:5.0-alpine
16+
container_name: redis-replica
17+
command:
18+
- redis-server
19+
- --port
20+
- "16380"
21+
- --replicaof
22+
- redis-master
23+
- "16379"
24+
depends_on:
25+
- redis-master
26+
ports:
27+
- "16380:16380"
28+
networks:
29+
- sentinel-cluster
30+
31+
redis-sentinel-1:
32+
image: ghcr.io/getsentry/image-mirror-library-redis:5.0-alpine
33+
container_name: redis-sentinel-1
34+
command:
35+
- sh
36+
- -ec
37+
- |
38+
cat <<EOF > /sentinel.conf
39+
port 26379
40+
sentinel monitor redis-sentry redis-master 16379 2
41+
sentinel down-after-milliseconds redis-sentry 5000
42+
sentinel parallel-syncs redis-sentry 1
43+
sentinel failover-timeout redis-sentry 10000
44+
EOF
45+
exec redis-server /sentinel.conf --sentinel
46+
depends_on:
47+
- redis-master
48+
- redis-replica
49+
ports:
50+
- "26379:26379"
51+
networks:
52+
- sentinel-cluster
53+
54+
redis-sentinel-2:
55+
image: ghcr.io/getsentry/image-mirror-library-redis:5.0-alpine
56+
container_name: redis-sentinel-2
57+
command:
58+
- sh
59+
- -ec
60+
- |
61+
cat <<EOF > /sentinel.conf
62+
port 26380
63+
sentinel monitor redis-sentry redis-master 16379 2
64+
sentinel down-after-milliseconds redis-sentry 5000
65+
sentinel parallel-syncs redis-sentry 1
66+
sentinel failover-timeout redis-sentry 10000
67+
EOF
68+
exec redis-server /sentinel.conf --sentinel
69+
depends_on:
70+
- redis-master
71+
- redis-replica
72+
ports:
73+
- "26380:26380"
74+
networks:
75+
- sentinel-cluster
76+
77+
networks:
78+
sentinel-cluster:

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ jobs:
777777
with:
778778
python-version: "3.11"
779779

780+
- name: Start Redis Sentinel cluster
781+
uses: ./.github/actions/sentinel-cluster
782+
780783
- run: make test-integration
781784
env:
782785
PYTEST_N: 6

tests/integration/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,9 @@ def redis_client():
263263
@pytest.fixture
264264
def secondary_redis_client():
265265
return redis.Redis(host="127.0.0.1", port=6380, db=0)
266+
267+
268+
@pytest.fixture
269+
def redis_sentinel_client():
270+
sentinel = redis.sentinel.Sentinel([("127.0.0.1", 26379), ("127.0.0.1", 26380)])
271+
return sentinel.discover_master("redis-sentry")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from sentry_sdk.envelope import Envelope
2+
3+
SENTINEL_CONFIG = {
4+
"processing": {
5+
"redis": {
6+
"sentinel_nodes": [
7+
"redis://127.0.0.1:26379",
8+
"redis://127.0.0.1:26380",
9+
],
10+
"master_name": "redis-sentry",
11+
}
12+
}
13+
}
14+
15+
16+
def test_redis_sentinel(redis_sentinel_client):
17+
assert redis_sentinel_client, "Failed to discover redis master"
18+
19+
20+
def test_startup_with_redis_sentinel(relay_with_processing):
21+
upstream = relay_with_processing(SENTINEL_CONFIG)
22+
assert upstream.wait_relay_health_check() is None, "Failed to start Relay"
23+
24+
25+
def test_envelope_with_redis_sentinel(mini_sentry, relay_with_processing):
26+
project_id = 42
27+
mini_sentry.add_basic_project_config(project_id)
28+
29+
envelope = Envelope()
30+
envelope.add_event({"message": "Hello, World!"})
31+
32+
upstream = relay_with_processing(SENTINEL_CONFIG)
33+
response = upstream.send_envelope(
34+
project_id,
35+
envelope,
36+
)
37+
38+
assert response, "Failed to send event"
39+
40+
event = mini_sentry.captured_events.get(timeout=1).get_event()
41+
assert event["logentry"] == {"formatted": "Hello, World!"}

0 commit comments

Comments
 (0)