diff --git a/src/libkernelbot/launchers/modal.py b/src/libkernelbot/launchers/modal.py index 5fb1a15e..1512dfbf 100644 --- a/src/libkernelbot/launchers/modal.py +++ b/src/libkernelbot/launchers/modal.py @@ -20,7 +20,6 @@ def __init__(self, add_include_dirs: list): async def run_submission( self, config: dict, gpu_type: GPU, status: RunProgressReporter ) -> FullResult: - loop = asyncio.get_event_loop() if config["lang"] == "cu": config["include_dirs"] = config.get("include_dirs", []) + self.additional_include_dirs func_name = self._function_name(config, gpu_type) @@ -29,10 +28,8 @@ async def run_submission( await status.push("⏳ Waiting for Modal run to finish...") - result = await loop.run_in_executor( - None, - lambda: modal.Function.from_name("discord-bot-runner", func_name).remote(config=config), - ) + function = modal.Function.from_name("discord-bot-runner", func_name) + result = await function.remote.aio(config=config) await status.update("✅ Waiting for modal run to finish... Done") diff --git a/tests/test_modal.py b/tests/test_modal.py index f2f7721f..fd3a9c32 100644 --- a/tests/test_modal.py +++ b/tests/test_modal.py @@ -4,7 +4,7 @@ from pathlib import Path from types import SimpleNamespace from typing import Tuple -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch import pytest @@ -29,6 +29,26 @@ async def update(self, message: str): self.updates.append(message) +@pytest.mark.asyncio +async def test_modal_submission_uses_native_async_api(): + launcher = ModalLauncher(add_include_dirs=["/extra/include"]) + reporter = MockProgressReporter() + function = MagicMock() + expected = object() + function.remote.aio = AsyncMock(return_value=expected) + config = {"lang": "cu"} + + with patch("libkernelbot.launchers.modal.modal.Function.from_name", return_value=function): + result = await launcher.run_submission(config, get_gpu_by_name("B200"), reporter) + + assert result is expected + assert config["include_dirs"] == ["/extra/include"] + function.remote.aio.assert_awaited_once_with(config=config) + function.remote.assert_not_called() + assert reporter.messages == ["⏳ Waiting for Modal run to finish..."] + assert reporter.updates == ["✅ Waiting for modal run to finish... Done"] + + @pytest.mark.asyncio async def test_modal_queue_status_uses_function_stats(): launcher = ModalLauncher(add_include_dirs=[])