test: harden timing-fragile test and add cross-tool ContextVar isolation test
Replace asyncio.sleep(0.05) with an asyncio.Event + patched Lock.acquire to guarantee the waiting task has reached the lock before asserting. Add a test confirming LongTaskTool and CompleteGoalTool ContextVars are isolated, and document the design intent in _GoalToolsMixin.
This commit is contained in:
1 parent
0df60416ba
commit
84428136e6
3 files changed
+34
-4
No files matched your search
@@ -46,6 +46,9 @@ class _GoalToolsMixin(ContextAware):
|
||||
def __init__(self, sessions: SessionManager, bus: Any | None = None) -> None:
|
||||
self._sessions = sessions
|
||||
self._bus = bus
|
||||
# Each subclass gets its own ContextVar so concurrent tasks across
|
||||
# different tool types (LongTaskTool vs CompleteGoalTool) do not
|
||||
# interfere with each other.
|
||||
self._request_ctx: ContextVar[RequestContext | None] = ContextVar(
|
||||
f"{self.__class__.__name__}_request_ctx",
|
||||
default=None,
|
||||
|
||||
Reference in new issue
Block a user