Skip to content

Commit fde9dc8

Browse files
committed
Clean up test code: remove useless comments and replace sleeps with events
- Remove redundant '# Should not raise' comments in test_capabilities.py - Remove redundant '# No handler' comments in test_server_task_context.py - Replace arbitrary sleeps with deterministic event-based synchronization in test_task_result_handler.py (poll for wait events before proceeding)
1 parent 05e19de commit fde9dc8

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

tests/experimental/tasks/server/test_server_task_context.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ async def test_elicit_raises_without_handler() -> None:
228228
store=store,
229229
session=mock_session,
230230
queue=queue,
231-
handler=None, # No handler
231+
handler=None,
232232
)
233233

234234
with pytest.raises(RuntimeError, match="handler is required"):
@@ -251,7 +251,7 @@ async def test_elicit_url_raises_without_handler() -> None:
251251
store=store,
252252
session=mock_session,
253253
queue=queue,
254-
handler=None, # No handler
254+
handler=None,
255255
)
256256

257257
with pytest.raises(RuntimeError, match="handler is required for elicit_url"):
@@ -278,7 +278,7 @@ async def test_create_message_raises_without_handler() -> None:
278278
store=store,
279279
session=mock_session,
280280
queue=queue,
281-
handler=None, # No handler
281+
handler=None,
282282
)
283283

284284
with pytest.raises(RuntimeError, match="handler is required"):
@@ -662,7 +662,7 @@ async def test_elicit_as_task_raises_without_handler() -> None:
662662
store=store,
663663
session=mock_session,
664664
queue=queue,
665-
handler=None, # No handler
665+
handler=None,
666666
)
667667

668668
with pytest.raises(RuntimeError, match="handler is required for elicit_as_task"):
@@ -697,7 +697,7 @@ async def test_create_message_as_task_raises_without_handler() -> None:
697697
store=store,
698698
session=mock_session,
699699
queue=queue,
700-
handler=None, # No handler
700+
handler=None,
701701
)
702702

703703
with pytest.raises(RuntimeError, match="handler is required for create_message_as_task"):

tests/experimental/tasks/server/test_task_result_handler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ async def run_handle() -> None:
151151

152152
async with anyio.create_task_group() as tg:
153153
tg.start_soon(run_handle)
154-
await anyio.sleep(0.05)
154+
155+
# Wait for handler to start waiting (event gets created when wait starts)
156+
while task.taskId not in store._update_events:
157+
await anyio.sleep(0)
155158

156159
await store.store_result(task.taskId, CallToolResult(content=[TextContent(type="text", text="Done")]))
157160
await store.update_task(task.taskId, status="completed")
@@ -303,7 +306,9 @@ async def failing_wait(task_id: str) -> None:
303306

304307
# Queue a message to unblock the race via the queue path
305308
async def enqueue_later() -> None:
306-
await anyio.sleep(0.01)
309+
# Wait for queue to start waiting (event gets created when wait starts)
310+
while task.taskId not in queue._events:
311+
await anyio.sleep(0)
307312
await queue.enqueue(
308313
task.taskId,
309314
QueuedMessage(
@@ -338,7 +343,9 @@ async def failing_wait(task_id: str) -> None:
338343

339344
# Update the store to unblock the race via the store path
340345
async def update_later() -> None:
341-
await anyio.sleep(0.01)
346+
# Wait for store to start waiting (event gets created when wait starts)
347+
while task.taskId not in store._update_events:
348+
await anyio.sleep(0)
342349
await store.update_task(task.taskId, status="completed")
343350

344351
async with anyio.create_task_group() as tg:

tests/experimental/tasks/test_capabilities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def test_passes_when_present(self) -> None:
252252
)
253253
)
254254
)
255-
require_task_augmented_elicitation(caps) # Should not raise
255+
require_task_augmented_elicitation(caps)
256256

257257

258258
class TestRequireTaskAugmentedSampling:
@@ -280,4 +280,4 @@ def test_passes_when_present(self) -> None:
280280
)
281281
)
282282
)
283-
require_task_augmented_sampling(caps) # Should not raise
283+
require_task_augmented_sampling(caps)

0 commit comments

Comments
 (0)