Skip to content

Commit 743f55d

Browse files
committed
Actually set the timeout in timeout test cases
1 parent 810566f commit 743f55d

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/lmstudio/json_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ def is_finished(self) -> bool:
695695
def _set_result(self, result: T) -> ChannelFinishedEvent:
696696
# Note: errors are raised immediately when handling the relevant message
697697
# rather than only being reported when the result is accessed
698+
self._logger.debug("Channel result received, closing channel")
698699
self._is_finished = True
699700
self._result = result
700701
return ChannelFinishedEvent(None)

tests/test_timeouts.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
get_sync_api_timeout,
1515
set_sync_api_timeout,
1616
)
17+
from lmstudio.sync_api import _DEFAULT_TIMEOUT
1718

1819
from .support import EXPECTED_LLM_ID
1920

@@ -22,40 +23,51 @@
2223

2324
@contextmanager
2425
def sync_api_timeout(timeout: float | None) -> Generator[float | None, None, None]:
25-
default_timeout = get_sync_api_timeout()
26+
previous_timeout = get_sync_api_timeout()
27+
set_sync_api_timeout(timeout)
2628
try:
27-
yield default_timeout
29+
yield previous_timeout
2830
finally:
29-
set_sync_api_timeout(default_timeout)
31+
set_sync_api_timeout(previous_timeout)
32+
33+
34+
def test_default_timeout() -> None:
35+
# Ensure default timeout is defined, but is not excessively short or long
36+
# (the bounds that are considered reasonable may change over time)
37+
assert _DEFAULT_TIMEOUT is not None
38+
assert _DEFAULT_TIMEOUT >= 60
39+
assert _DEFAULT_TIMEOUT <= 600
3040

3141

3242
@pytest.mark.parametrize("timeout", (None, 0, 1.5, 3600, 3600 * 24 * 7))
3343
def test_timeout_updates_sync(timeout: float | None) -> None:
3444
with sync_api_timeout(timeout) as previous_timeout:
35-
assert previous_timeout is not None
36-
assert previous_timeout > 0
37-
set_sync_api_timeout(timeout)
45+
assert previous_timeout == _DEFAULT_TIMEOUT
3846
assert get_sync_api_timeout() == timeout
3947
assert get_sync_api_timeout() == previous_timeout
4048

4149

4250
@pytest.mark.lmstudio
43-
def test_rpc_timeout_sync(caplog: LogCap) -> None:
51+
def test_timeout_rpc_sync(caplog: LogCap) -> None:
4452
caplog.set_level(logging.DEBUG)
4553

4654
with Client() as client:
4755
model = client.llm.model(EXPECTED_LLM_ID)
4856
with sync_api_timeout(0):
57+
assert get_sync_api_timeout() == 0
4958
with pytest.raises(LMStudioTimeoutError):
50-
model.get_info()
59+
response = model.get_info()
60+
logging.error(f"Unexpected response: {response}")
5161

5262

5363
@pytest.mark.lmstudio
54-
def test_channel_timeout_sync(caplog: LogCap) -> None:
64+
def test_timeout_channel_sync(caplog: LogCap) -> None:
5565
caplog.set_level(logging.DEBUG)
5666

5767
with Client() as client:
5868
model = client.llm.model(EXPECTED_LLM_ID)
5969
with sync_api_timeout(0):
70+
assert get_sync_api_timeout() == 0
6071
with pytest.raises(LMStudioTimeoutError):
61-
model.respond("This will time out")
72+
response = model.respond("This will time out")
73+
logging.error(f"Unexpected response: {response}")

0 commit comments

Comments
 (0)