Skip to content

Commit 7cb14a2

Browse files
charlesfryeModal
andauthored
fix: Resolve AsyncUsageWarning in test_case_generator example (#1493)
Co-authored-by: Modal <modal@example.com>
1 parent b1bc8c0 commit 7cb14a2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

13_sandboxes/test_case_generator.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def get_sandbox_image(gh_owner: str, gh_repo_name: str):
273273
# coverage, and show the results of both in ports 8000 and 8001.
274274

275275

276-
def run_sandbox(image: modal.Image, file_name: str):
276+
async def run_sandbox(image: modal.Image, file_name: str):
277277
new_file_name = file_name.replace(".py", "_llm.py")
278278

279279
cmd = (
@@ -290,7 +290,7 @@ def run_sandbox(image: modal.Image, file_name: str):
290290
+ "allure serve allure-results --host 0.0.0.0 --port 8000"
291291
)
292292

293-
sb = modal.Sandbox.create(
293+
sb = await modal.Sandbox.create.aio(
294294
"sh",
295295
"-c",
296296
cmd,
@@ -345,7 +345,7 @@ async def main(
345345
print("Test case files generated successfully! Creating sandboxes...")
346346

347347
# Create sandboxes to run the generated test files
348-
sandboxes = create_sandboxes(output_files, gh_owner, gh_repo_name)
348+
sandboxes = await create_sandboxes(output_files, gh_owner, gh_repo_name)
349349
await asyncio.gather(
350350
*[sb.wait.aio(raise_on_termination=False) for sb in sandboxes],
351351
return_exceptions=True,
@@ -360,18 +360,19 @@ async def main(
360360
import time
361361

362362

363-
def create_sandboxes(filenames: list[str], gh_owner: str, gh_repo_name: str):
363+
async def create_sandboxes(filenames: list[str], gh_owner: str, gh_repo_name: str):
364364
file_to_sandbox: dict[str, modal.Sandbox] = {}
365365
for filename in filenames:
366366
print(f"Running sandbox for {filename}")
367367
image = get_sandbox_image(gh_owner, gh_repo_name)
368-
sb = run_sandbox(image, filename)
368+
sb = await run_sandbox(image, filename)
369369
file_to_sandbox[filename] = sb
370370
time.sleep(20) # Hack to make sure URLs show up at the very end
371371

372372
for filename, sb in file_to_sandbox.items():
373-
tunnel1 = sb.tunnels()[8000]
374-
tunnel2 = sb.tunnels()[8001]
373+
tunnels = await sb.tunnels.aio()
374+
tunnel1 = tunnels[8000]
375+
tunnel2 = tunnels[8001]
375376
print(f"Sandbox created and run for generated test file: {filename}")
376377
print(f"✨ View diff: {tunnel2.url}")
377378
print(f"✨ View test results: {tunnel1.url}\n")

0 commit comments

Comments
 (0)