|
8 | 8 | from redis.asyncio.cluster import RedisCluster
|
9 | 9 |
|
10 | 10 |
|
| 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 | + |
11 | 19 | async def pipe(
|
12 | 20 | reader: asyncio.StreamReader,
|
13 | 21 | writer: asyncio.StreamWriter,
|
@@ -68,18 +76,16 @@ async def stop(self):
|
68 | 76 |
|
69 | 77 | @pytest.mark.onlynoncluster
|
70 | 78 | @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): |
72 | 80 |
|
73 | 81 | # create a tcp socket proxy that relays data to Redis and back,
|
74 | 82 | # 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) |
78 | 84 | await dp.start()
|
79 | 85 |
|
80 | 86 | for b in [True, False]:
|
81 | 87 | # 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: |
83 | 89 |
|
84 | 90 | with dp.override():
|
85 | 91 | await r.set("foo", "foo")
|
@@ -107,13 +113,11 @@ async def test_standalone(delay):
|
107 | 113 |
|
108 | 114 | @pytest.mark.onlynoncluster
|
109 | 115 | @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) |
114 | 118 | await dp.start()
|
115 | 119 | 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: |
117 | 121 | with dp.override():
|
118 | 122 | await r.set("foo", "foo")
|
119 | 123 | await r.set("bar", "bar")
|
@@ -156,12 +160,13 @@ async def test_standalone_pipeline(delay):
|
156 | 160 |
|
157 | 161 |
|
158 | 162 | @pytest.mark.onlycluster
|
159 |
| -async def test_cluster(request): |
| 163 | +async def test_cluster(request, redis_addr): |
160 | 164 |
|
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) |
162 | 167 | await dp.start()
|
163 | 168 |
|
164 |
| - r = RedisCluster.from_url("redis://localhost:5381") |
| 169 | + r = RedisCluster.from_url("redis://127.0.0.1:5381") |
165 | 170 | await r.initialize()
|
166 | 171 | with dp.override():
|
167 | 172 | await r.set("foo", "foo")
|
|
0 commit comments