|
1 | 1 | import json |
2 | 2 | from pathlib import Path |
3 | 3 |
|
4 | | -import redis |
5 | 4 | import subprocess |
6 | 5 |
|
7 | | -from .util import ( |
8 | | - docker_run, |
9 | | - get_local_ip, |
10 | | - random_string, |
11 | | -) |
| 6 | +from .util import docker_run, random_string |
12 | 7 |
|
13 | 8 |
|
14 | | -def test_queue_worker_yielding(docker_image, redis_port): |
| 9 | +def test_queue_worker_yielding(docker_image, docker_network, redis_client): |
15 | 10 | project_dir = Path(__file__).parent / "fixtures/yielding-project" |
16 | 11 | subprocess.run(["cog", "build", "-t", docker_image], check=True, cwd=project_dir) |
17 | 12 |
|
18 | | - local_ip = get_local_ip() |
19 | | - redis_host = local_ip |
20 | | - |
21 | | - redis_client = redis.Redis(host=redis_host, port=redis_port, db=0) |
22 | | - |
23 | 13 | with docker_run( |
24 | 14 | image=docker_image, |
25 | 15 | interactive=True, |
| 16 | + network=docker_network, |
26 | 17 | command=[ |
27 | 18 | "python", |
28 | 19 | "-m", |
29 | 20 | "cog.server.redis_queue", |
30 | | - redis_host, |
31 | | - str(redis_port), |
| 21 | + "redis", |
| 22 | + "6379", |
32 | 23 | "predict-queue", |
33 | 24 | "", |
34 | 25 | "test-worker", |
@@ -69,24 +60,20 @@ def test_queue_worker_yielding(docker_image, redis_port): |
69 | 60 | assert response == None |
70 | 61 |
|
71 | 62 |
|
72 | | -def test_queue_worker_error(docker_image, redis_port, request): |
| 63 | +def test_queue_worker_error(docker_image, docker_network, redis_client): |
73 | 64 | project_dir = Path(__file__).parent / "fixtures/failing-project" |
74 | 65 | subprocess.run(["cog", "build", "-t", docker_image], check=True, cwd=project_dir) |
75 | 66 |
|
76 | | - local_ip = get_local_ip() |
77 | | - redis_host = local_ip |
78 | | - |
79 | | - redis_client = redis.Redis(host=redis_host, port=redis_port, db=0) |
80 | | - |
81 | 67 | with docker_run( |
82 | 68 | image=docker_image, |
83 | 69 | interactive=True, |
| 70 | + network=docker_network, |
84 | 71 | command=[ |
85 | 72 | "python", |
86 | 73 | "-m", |
87 | 74 | "cog.server.redis_queue", |
88 | | - redis_host, |
89 | | - str(redis_port), |
| 75 | + "redis", |
| 76 | + "6379", |
90 | 77 | "predict-queue", |
91 | 78 | "", |
92 | 79 | "test-worker", |
@@ -121,24 +108,20 @@ def test_queue_worker_error(docker_image, redis_port, request): |
121 | 108 | assert response == None |
122 | 109 |
|
123 | 110 |
|
124 | | -def test_queue_worker_logging(docker_image, redis_port, request): |
| 111 | +def test_queue_worker_logging(docker_image, docker_network, redis_client): |
125 | 112 | project_dir = Path(__file__).parent / "fixtures/logging-project" |
126 | 113 | subprocess.run(["cog", "build", "-t", docker_image], check=True, cwd=project_dir) |
127 | 114 |
|
128 | | - local_ip = get_local_ip() |
129 | | - redis_host = local_ip |
130 | | - |
131 | | - redis_client = redis.Redis(host=redis_host, port=redis_port, db=0) |
132 | | - |
133 | 115 | with docker_run( |
134 | 116 | image=docker_image, |
135 | 117 | interactive=True, |
| 118 | + network=docker_network, |
136 | 119 | command=[ |
137 | 120 | "python", |
138 | 121 | "-m", |
139 | 122 | "cog.server.redis_queue", |
140 | | - redis_host, |
141 | | - str(redis_port), |
| 123 | + "redis", |
| 124 | + "6379", |
142 | 125 | "predict-queue", |
143 | 126 | "", |
144 | 127 | "test-worker", |
@@ -189,24 +172,20 @@ def test_queue_worker_logging(docker_image, redis_port, request): |
189 | 172 | ] |
190 | 173 |
|
191 | 174 |
|
192 | | -def test_queue_worker_timeout(docker_image, redis_port, request): |
| 175 | +def test_queue_worker_timeout(docker_image, docker_network, redis_client): |
193 | 176 | project_dir = Path(__file__).parent / "fixtures/timeout-project" |
194 | 177 | subprocess.run(["cog", "build", "-t", docker_image], check=True, cwd=project_dir) |
195 | 178 |
|
196 | | - local_ip = get_local_ip() |
197 | | - redis_host = local_ip |
198 | | - |
199 | | - redis_client = redis.Redis(host=redis_host, port=redis_port, db=0) |
200 | | - |
201 | 179 | with docker_run( |
202 | 180 | image=docker_image, |
203 | 181 | interactive=True, |
| 182 | + network=docker_network, |
204 | 183 | command=[ |
205 | 184 | "python", |
206 | 185 | "-m", |
207 | 186 | "cog.server.redis_queue", |
208 | | - redis_host, |
209 | | - str(redis_port), |
| 187 | + "redis", |
| 188 | + "6379", |
210 | 189 | "predict-queue", |
211 | 190 | "", |
212 | 191 | "test-worker", |
@@ -258,24 +237,20 @@ def test_queue_worker_timeout(docker_image, redis_port, request): |
258 | 237 | assert response == {"status": "failed", "error": "Prediction timed out"} |
259 | 238 |
|
260 | 239 |
|
261 | | -def test_queue_worker_yielding_timeout(docker_image, redis_port, request): |
| 240 | +def test_queue_worker_yielding_timeout(docker_image, docker_network, redis_client): |
262 | 241 | project_dir = Path(__file__).parent / "fixtures/yielding-timeout-project" |
263 | 242 | subprocess.run(["cog", "build", "-t", docker_image], check=True, cwd=project_dir) |
264 | 243 |
|
265 | | - local_ip = get_local_ip() |
266 | | - redis_host = local_ip |
267 | | - |
268 | | - redis_client = redis.Redis(host=redis_host, port=redis_port, db=0) |
269 | | - |
270 | 244 | with docker_run( |
271 | 245 | image=docker_image, |
272 | 246 | interactive=True, |
| 247 | + network=docker_network, |
273 | 248 | command=[ |
274 | 249 | "python", |
275 | 250 | "-m", |
276 | 251 | "cog.server.redis_queue", |
277 | | - redis_host, |
278 | | - str(redis_port), |
| 252 | + "redis", |
| 253 | + "6379", |
279 | 254 | "predict-queue", |
280 | 255 | "", |
281 | 256 | "test-worker", |
|
0 commit comments