Skip to content

Commit 1844efa

Browse files
committed
Use provided redis address. Use DelayProxy over local ipv4 only.
1 parent ac4ff78 commit 1844efa

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

tests/test_asyncio/test_cwe_404.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import asyncio
22
import contextlib
3-
import sys
43

54
import pytest
65

76
from redis.asyncio import Redis
87
from redis.asyncio.cluster import RedisCluster
98

109

10+
@pytest.fixture
11+
def redis_addr(request):
12+
redis_url = request.config.getoption("--redis-url")
13+
assert redis_url.startswith("redis://")
14+
host, port = redis_url[8:].split(":")
15+
return host, int(port)
16+
17+
1118
async def pipe(
1219
reader: asyncio.StreamReader,
1320
writer: asyncio.StreamWriter,
@@ -68,18 +75,16 @@ async def stop(self):
6875

6976
@pytest.mark.onlynoncluster
7077
@pytest.mark.parametrize("delay", argvalues=[0.05, 0.5, 1, 2])
71-
async def test_standalone(delay):
78+
async def test_standalone(delay, redis_addr):
7279

7380
# create a tcp socket proxy that relays data to Redis and back,
7481
# inserting 0.1 seconds of delay
75-
dp = DelayProxy(
76-
addr=("localhost", 5380), redis_addr=("localhost", 6379), delay=delay * 2
77-
)
82+
dp = DelayProxy(addr=("127.0.0.1", 5380), redis_addr=redis_addr, delay=delay * 2)
7883
await dp.start()
7984

8085
for b in [True, False]:
8186
# note that we connect to proxy, rather than to Redis directly
82-
async with Redis(host="localhost", port=5380, single_connection_client=b) as r:
87+
async with Redis(host="127.0.0.1", port=5380, single_connection_client=b) as r:
8388

8489
with dp.override():
8590
await r.set("foo", "foo")
@@ -107,13 +112,11 @@ async def test_standalone(delay):
107112

108113
@pytest.mark.onlynoncluster
109114
@pytest.mark.parametrize("delay", argvalues=[0.05, 0.5, 1, 2])
110-
async def test_standalone_pipeline(delay):
111-
dp = DelayProxy(
112-
addr=("localhost", 5380), redis_addr=("localhost", 6379), delay=delay * 2
113-
)
115+
async def test_standalone_pipeline(delay, redis_addr):
116+
dp = DelayProxy(addr=("127.0.0.1", 5380), redis_addr=redis_addr, delay=delay * 2)
114117
await dp.start()
115118
for b in [True, False]:
116-
async with Redis(host="localhost", port=5380, single_connection_client=b) as r:
119+
async with Redis(host="127.0.0.1", port=5380, single_connection_client=b) as r:
117120
with dp.override():
118121
await r.set("foo", "foo")
119122
await r.set("bar", "bar")
@@ -156,12 +159,13 @@ async def test_standalone_pipeline(delay):
156159

157160

158161
@pytest.mark.onlycluster
159-
async def test_cluster(request):
162+
async def test_cluster(request, redis_addr):
160163

161-
dp = DelayProxy(addr=("localhost", 5381), redis_addr=("localhost", 6372), delay=0.1)
164+
redis_addr = redis_addr[0], 6372 # use the cluster port
165+
dp = DelayProxy(addr=("127.0.0.1", 5381), redis_addr=redis_addr, delay=0.1)
162166
await dp.start()
163167

164-
r = RedisCluster.from_url("redis://localhost:5381")
168+
r = RedisCluster.from_url("redis://127.0.0.1:5381")
165169
await r.initialize()
166170
with dp.override():
167171
await r.set("foo", "foo")

0 commit comments

Comments
 (0)