Skip to content

Commit 4477151

Browse files
authored
test(integration): make a test stable by removing time constraints (#214)
1 parent be97cfc commit 4477151

3 files changed

Lines changed: 22 additions & 38 deletions

File tree

‎src/language_tool_python/download_lt.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ def download(self) -> None:
752752
return
753753

754754
if self not in self.get_installed_versions():
755-
with ( # pragma: no cover # integration: HTTP download + extraction
755+
# In test env, LT is probably already installed, so this branch is not
756+
# taken, but the ZIP extraction code is tested in unit and property tests
757+
with ( # pragma: no cover
756758
tempfile.TemporaryDirectory(dir=download_folder) as temp_dir,
757759
tempfile.NamedTemporaryFile(
758760
suffix=".zip",

‎src/language_tool_python/server.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
from .utils import correct
4545

4646
_startupinfo: object | None = None
47-
if sys.platform == "win32":
47+
# Windows-specific code, coverage is measured on Linux
48+
if sys.platform == "win32": # pragma: no cover
4849
_startupinfo = subprocess.STARTUPINFO()
4950
_startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
5051

‎tests/integration/test_config.py‎

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Integration tests for LanguageTool configuration options (require a local server)."""
22

33
import re
4-
import time
54

65
import pytest
76

@@ -131,47 +130,29 @@ def test_config_text_length() -> None:
131130

132131

133132
def test_config_caching() -> None:
134-
"""Test the caching configuration parameters.
135-
136-
This test verifies that LanguageTool's caching mechanism (cacheSize and
137-
pipelineCaching) significantly improves performance when checking the same text
138-
multiple times. The test measures the time difference between an uncached and a
139-
cached check to ensure caching provides a substantial speedup.
140-
141-
This is inherently a timing-sensitive test and could still be flaky under heavy
142-
machine load, so it: (1) performs a warm-up check on unrelated text before
143-
timing, to exclude one-off JIT/connection-setup costs from the measurement
144-
without pre-populating the cache for the text under test, and (2) repeats the
145-
timed comparison up to ``_ATTEMPTS`` times, succeeding as soon as one attempt
146-
shows the expected speedup, instead of requiring every attempt to pass.
147-
148-
:raises AssertionError: If caching does not provide the expected performance
149-
improvement in any attempt.
150-
"""
151-
speedup_factor = 5.0
152-
attempts = 3
133+
"""Test that the caching configuration parameters are accepted by the server.
134+
135+
This test verifies that LanguageTool starts successfully and correctly checks
136+
text when configured with ``cacheSize`` and ``pipelineCaching``, including when
137+
the same sentence is checked twice in a row (the second call takes the cache
138+
hit code path server-side).
139+
140+
The actual speedup these options provide is a wall-clock measurement, which is
141+
too noisy on shared CI runners to gate pass/fail on: it belongs in the
142+
``perf``-marked benchmark suite (see ``test_bench_check_with_pipeline_cache`` in
143+
``tests/benchmarks/test_bench_check.py``), which is opt-in and does not affect
144+
CI results.
153145
146+
:raises AssertionError: If the tool fails to produce matches under this config.
147+
"""
154148
with language_tool_python.LanguageTool(
155149
"en-US",
156150
config={"cacheSize": 1000, "pipelineCaching": True},
157151
) as tool:
158-
tool.check("warm-up text unrelated to the cached sentence below")
159-
160152
s = "hello darkness my old frend"
161-
for _ in range(attempts):
162-
t1 = time.time()
163-
tool.check(s)
164-
t2 = time.time()
165-
tool.check(s)
166-
t3 = time.time()
167-
168-
# In practice, speedups of around 250x (6.76s to 0.028s) have been observed.
169-
if (t2 - t1) / speedup_factor > (t3 - t2):
170-
return
171-
172-
pytest.fail(
173-
f"Caching did not provide the expected speedup in {attempts} attempts."
174-
)
153+
assert len(tool.check(s)) > 0
154+
# Second check of the same sentence exercises the cache-hit path.
155+
assert len(tool.check(s)) > 0
175156

176157

177158
def test_inexistent_language() -> None:

0 commit comments

Comments
 (0)