Skip to content

Commit 95eb92f

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

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

tests/test_asyncio/test_cwe_404.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
from redis.asyncio.cluster import RedisCluster
99

1010

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

6977
@pytest.mark.onlynoncluster
7078
@pytest.mark.parametrize("delay", argvalues=[0.05, 0.5, 1, 2])
71-
async def test_standalone(delay):
79+
async def test_standalone(delay, redis_addr):
7280

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

8086
for b in [True, False]:
8187
# 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:
88+
async with Redis(host="127.0.0.1", port=5380, single_connection_client=b) as r:
8389

8490
with dp.override():
8591
await r.set("foo", "foo")
@@ -107,13 +113,11 @@ async def test_standalone(delay):
107113

108114
@pytest.mark.onlynoncluster
109115
@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-
)
116+
async def test_standalone_pipeline(delay, redis_addr):
117+
dp = DelayProxy(addr=("127.0.0.1", 5380), redis_addr=redis_addr, delay=delay * 2)
114118
await dp.start()
115119
for b in [True, False]:
116-
async with Redis(host="localhost", port=5380, single_connection_client=b) as r:
120+
async with Redis(host="127.0.0.1", port=5380, single_connection_client=b) as r:
117121
with dp.override():
118122
await r.set("foo", "foo")
119123
await r.set("bar", "bar")
@@ -156,12 +160,13 @@ async def test_standalone_pipeline(delay):
156160

157161

158162
@pytest.mark.onlycluster
159-
async def test_cluster(request):
163+
async def test_cluster(request, redis_addr):
160164

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

164-
r = RedisCluster.from_url("redis://localhost:5381")
169+
r = RedisCluster.from_url("redis://127.0.0.1:5381")
165170
await r.initialize()
166171
with dp.override():
167172
await r.set("foo", "foo")

0 commit comments

Comments
 (0)