Skip to content

Commit 8e56dda

Browse files
jrvb-rlclaude
andcommitted
Fix cross-loop test: compare transport identity, not id()
After close(), Python can reuse the freed memory address for the next transport, making id() values match across separate asyncio.run() calls. Keep the first transport reference alive and use `is not` instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 000479a commit 8e56dda

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

tests/test_shared_pool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,16 @@ class TestAsyncCrossLoop:
292292
def test_separate_loops_get_separate_transports(self):
293293
"""Clients created in different asyncio.run() calls must not share a transport."""
294294

295-
async def create_client() -> int:
295+
async def create_client() -> Any:
296296
c = _make_async_client(shared_http_pool=True)
297-
transport_id = id(_get_transport(c))
297+
transport = _get_transport(c)
298298
await c.close()
299-
return transport_id
299+
return transport
300300

301-
id1 = asyncio.run(create_client())
302-
id2 = asyncio.run(create_client())
301+
t1 = asyncio.run(create_client())
302+
t2 = asyncio.run(create_client())
303303

304-
assert id1 != id2, "each loop should get its own transport"
304+
assert t1 is not t2, "each loop should get its own transport"
305305

306306
def test_same_loop_shares_transport(self):
307307
"""Clients created in the same asyncio.run() must share a transport."""

0 commit comments

Comments
 (0)