From f2f4fea87064c802003535a968100f8f75811b87 Mon Sep 17 00:00:00 2001 From: Akshat Bubna Date: Fri, 6 Sep 2024 03:51:24 +0000 Subject: [PATCH] add test --- modal/app.py | 3 +-- test/conftest.py | 2 ++ test/container_test.py | 6 ++++++ test/supports/sandbox.py | 8 ++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/supports/sandbox.py diff --git a/modal/app.py b/modal/app.py index f01709fa0..e8bd9ef5e 100644 --- a/modal/app.py +++ b/modal/app.py @@ -124,6 +124,7 @@ def foo(): """ _all_apps: ClassVar[Dict[Optional[str], List["_App"]]] = {} + _container_app: ClassVar[Optional[RunningApp]] = None _name: Optional[str] _description: Optional[str] @@ -141,8 +142,6 @@ def foo(): _running_app: Optional[RunningApp] # Various app info _client: Optional[_Client] - _container_app: ClassVar[Optional[RunningApp]] = None - def __init__( self, name: Optional[str] = None, diff --git a/test/conftest.py b/test/conftest.py index cd7e8f4fc..3761fccfe 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -192,6 +192,7 @@ def __init__(self, blob_host, blobs): self.volume_reloads: Dict[str, int] = defaultdict(lambda: 0) self.sandbox_defs = [] + self.sandbox_app_id = None self.sandbox: asyncio.subprocess.Process = None self.sandbox_result: Optional[api_pb2.GenericResult] = None @@ -1181,6 +1182,7 @@ async def SandboxCreate(self, stream): stdin=asyncio.subprocess.PIPE, ) + self.sandbox_app_id = request.app_id self.sandbox_defs.append(request.definition) await stream.send_message(api_pb2.SandboxCreateResponse(sandbox_id="sb-123")) diff --git a/test/container_test.py b/test/container_test.py index b0571c2a1..ae905f99e 100644 --- a/test/container_test.py +++ b/test/container_test.py @@ -2065,3 +2065,9 @@ def test_max_concurrency(servicer): outputs = [deserialize(item.result.data, ret.client) for item in ret.items] assert n_inputs in outputs + + +@skip_github_non_linux +def test_sandbox_infers_app(servicer, event_loop): + _run_container(servicer, "test.supports.sandbox", "spawn_sandbox") + assert servicer.sandbox_app_id == "ap-1" diff --git a/test/supports/sandbox.py b/test/supports/sandbox.py new file mode 100644 index 000000000..ca8a7c194 --- /dev/null +++ b/test/supports/sandbox.py @@ -0,0 +1,8 @@ +import modal + +app = modal.App() + + +@app.function() +def spawn_sandbox(x): + modal.Sandbox.create("bash", "-c", "echo bar")