Skip to content

Commit a607041

Browse files
committed
test: improve test clarity and modernize asyncio usage
- Add explanation for 200ms timeout in backpressure test - Replace manual event loop creation with asyncio.run() - Add assertion message with actual elapsed time for easier debugging
1 parent ddd3159 commit a607041

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

tests/test_resources_api.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,10 @@ def test_resource_list_filters_and_rejects_traversal(resource_tools, tmp_path, m
8080
list_resources = resource_tools["list_resources"]
8181
# Only .cs under Assets should be listed
8282
import asyncio
83-
loop = asyncio.new_event_loop()
84-
try:
85-
resp = loop.run_until_complete(
86-
list_resources(ctx=DummyContext(), pattern="*.cs", under="Assets",
87-
limit=50, project_root=str(proj))
88-
)
89-
finally:
90-
loop.close()
83+
resp = asyncio.run(
84+
list_resources(ctx=DummyContext(), pattern="*.cs", under="Assets",
85+
limit=50, project_root=str(proj))
86+
)
9187
assert resp["success"] is True
9288
uris = resp["data"]["uris"]
9389
assert any(u.endswith("Assets/Scripts/A.cs") for u in uris)
@@ -100,14 +96,10 @@ def test_resource_list_rejects_outside_paths(resource_tools, tmp_path):
10096
# under points outside Assets
10197
list_resources = resource_tools["list_resources"]
10298
import asyncio
103-
loop = asyncio.new_event_loop()
104-
try:
105-
resp = loop.run_until_complete(
106-
list_resources(ctx=DummyContext(), pattern="*.cs", under="..",
107-
limit=10, project_root=str(proj))
108-
)
109-
finally:
110-
loop.close()
99+
resp = asyncio.run(
100+
list_resources(ctx=DummyContext(), pattern="*.cs", under="..",
101+
limit=10, project_root=str(proj))
102+
)
111103
assert resp["success"] is False
112104
assert "Assets" in resp.get(
113105
"error", "") or "under project root" in resp.get("error", "")

tests/test_telemetry_queue_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def slow_send(self, rec):
8080
elapsed_ms = (time.perf_counter() - start) * 1000.0
8181

8282
# Should be fast despite backpressure (non-blocking enqueue or drop)
83-
assert elapsed_ms < 200.0
83+
# Timeout relaxed to 200ms to handle thread scheduling variance in CI/local environments
84+
assert elapsed_ms < 200.0, f"Took {elapsed_ms:.1f}ms (expected <200ms)"
8485

8586
# Allow worker to process some
8687
time.sleep(0.3)

0 commit comments

Comments
 (0)