Skip to content

Commit 0be344d

Browse files
committed
server : speed up tests
1 parent 186415d commit 0be344d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tools/server/tests/unit/test_basic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
server = ServerPreset.tinyllama2()
66

77

8+
@pytest.fixture(scope="session", autouse=True)
9+
def do_something():
10+
# this will be run once per test session, before any tests
11+
ServerPreset.load_all()
12+
13+
814
@pytest.fixture(autouse=True)
915
def create_server():
1016
global server

tools/server/tests/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ServerProcess:
4545
model_alias: str = "tinyllama-2"
4646
temperature: float = 0.8
4747
seed: int = 42
48+
offline: bool = True
4849

4950
# custom options
5051
model_alias: str | None = None
@@ -118,6 +119,8 @@ def start(self, timeout_seconds: int | None = DEFAULT_HTTP_TIMEOUT) -> None:
118119
"--seed",
119120
self.seed,
120121
]
122+
if self.offline:
123+
server_args.append("--offline")
121124
if self.model_file:
122125
server_args.extend(["--model", self.model_file])
123126
if self.model_url:
@@ -392,6 +395,19 @@ def make_any_request(
392395

393396

394397
class ServerPreset:
398+
@staticmethod
399+
def load_all() -> None:
400+
""" Load all server presets to ensure model files are cached. """
401+
servers: List[ServerProcess] = [
402+
method()
403+
for name, method in ServerPreset.__dict__.items()
404+
if callable(method) and name != "load_all"
405+
]
406+
for server in servers:
407+
server.offline = False
408+
server.start()
409+
server.stop()
410+
395411
@staticmethod
396412
def tinyllama2() -> ServerProcess:
397413
server = ServerProcess()

0 commit comments

Comments
 (0)