Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

OpenAPI loop test: build the real schema outside the measured window (#14346)

Daniel Han7ac1d2b7461d
diff --git a/studio/backend/tests/test_openapi_off_the_event_loop.py b/studio/backend/tests/test_openapi_off_the_event_loop.py
index a6e6c9a83b1..14d57a1e668 100644
--- a/studio/backend/tests/test_openapi_off_the_event_loop.py
+++ b/studio/backend/tests/test_openapi_off_the_event_loop.py
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Building the OpenAPI schema must not stall the event loop (#9712). The build is slowed so
-the result does not depend on machine speed."""
+"""Building the OpenAPI schema must not stall the event loop (#9712). The measured build is a
+sleep of _BUILD_S, so the result does not depend on machine speed."""
from __future__ import annotations
@@ -30,16 +30,23 @@ def main_module():
return _main
[email protected](scope = "module")
+def real_schema(main_module):
+ """The real schema, built before any loop is measured. Generating it holds the GIL in
+ stretches that grow with machine speed (1.6s on a loaded runner, against a 1.5s limit),
+ so it must not run inside the window the probe watches."""
+ return main_module.app.openapi()
+
+
@pytest.fixture
-def slow_cold_build(main_module, monkeypatch):
- """A cold schema cache whose build takes _BUILD_S and counts its calls."""
- real = fastapi.applications.get_openapi
+def slow_cold_build(main_module, real_schema, monkeypatch):
+ """A cold schema cache whose build sleeps _BUILD_S, returns the real schema, and counts its calls."""
calls = []
def slow(*args, **kwargs):
calls.append(threading.current_thread().name)
time.sleep(_BUILD_S)
- return real(*args, **kwargs)
+ return real_schema
monkeypatch.setattr(fastapi.applications, "get_openapi", slow)
saved = main_module.app.openapi_schema