@@ -237,13 +237,13 @@ async def test_tenant_context_isolation_between_concurrent_requests():
237237 2. Each simulated request:
238238 - Creates an AccessToken with its tenant_id
239239 - Sets it in the auth_context_var (the contextvar used for auth state)
240- - Yields control via anyio.sleep () to allow the other task to run
240+ - Yields control via checkpoint () to allow the other task to run
241241 - Reads back the tenant_id via get_tenant_id()
242242 - Stores the result for verification
243243
244- 3. The anyio.sleep(0.01) is intentional - it forces a context switch,
245- creating an opportunity for tenant context to "leak" if the isolation
246- is broken. Without proper contextvar isolation, task2 might see
244+ 3. The anyio.lowlevel.checkpoint() forces a context switch, creating
245+ an opportunity for tenant context to "leak" if the isolation is
246+ broken. Without proper contextvar isolation, task2 might see
247247 task1's tenant_id (or vice versa) after the context switch.
248248
249249 4. We use anyio.create_task_group() to run both tasks truly concurrently,
@@ -281,7 +281,7 @@ async def simulate_request(tenant_id: str, request_key: str) -> None:
281281 try :
282282 # Yield control to allow other tasks to run. This is the critical
283283 # point where context leakage could occur if isolation is broken.
284- await anyio .sleep ( 0.01 )
284+ await anyio .lowlevel . checkpoint ( )
285285
286286 # Read back the tenant_id - should still be our tenant, not the other
287287 results [request_key ] = tenant_id_var .get ()
0 commit comments