Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tst/unit/drivers/page_driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,11 @@ async def test_a_call_slower_than_its_bound_is_refused_and_its_session_opened_af
assert first.close.is_set() and not after.isError


async def _owners_left(within: float) -> list[asyncio.Task]:
"""The gateway's session owners still running once they've had ``within`` seconds to end."""
async def _owners_left(within: float, before: set[asyncio.Task]) -> list[asyncio.Task]:
"""The session owners started since ``before`` still running once they've had ``within`` seconds to end: the
loop is shared across the session, so an owner another test left running isn't this test's."""
deadline = asyncio.get_running_loop().time() + within
while (owners := [task for task in asyncio.all_tasks() if task.get_coro().__name__ == "_own"]) and (
while (owners := [task for task in asyncio.all_tasks() - before if task.get_coro().__name__ == "_own"]) and (
asyncio.get_running_loop().time() < deadline):
await asyncio.sleep(OWNERS_POLL_S)
return owners
Expand All @@ -578,12 +579,13 @@ async def _owners_left(within: float) -> list[asyncio.Task]:
async def test_a_call_is_bounded_from_when_it_asks_for_its_session_and_leaves_no_session_half_open(stand_in, monkeypatch):
module, playwright, endpoints, called = stand_in
monkeypatch.setattr(module, "CALL_BOUND_S", 1.0)
before = asyncio.all_tasks()
try:
async with playwright._lock:
waited = await asyncio.wait_for(called("ada"), 10)
endpoints.append("ws://127.0.0.1:18765/svc/chromium/cdp/wedged-once")
opening = await asyncio.wait_for(called("bo"), 10)
owners = await _owners_left(OWNERS_END_WITHIN_S)
owners = await _owners_left(OWNERS_END_WITHIN_S, before)
finally:
await playwright._stop()

Expand Down
35 changes: 19 additions & 16 deletions tst/unit/env/gateway/child_sessions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,22 +424,25 @@ async def test_a_reported_transport_failure_retires_the_session_once_and_the_nex
session = _FakeSession()
opener = _Opener(session)
gw = _gateway(opener)
first = await gw._sessions.ensure(URL)
gw._sessions.transport_failed(first, httpx.ReadError("peer went away"))
gw._sessions.transport_failed(first, httpx.ReadError("again")) # every request in flight reports; one retirement
assert len(gw._sessions.retirements) == 1
await asyncio.gather(*gw._sessions.retirements)
assert gw._sessions.retirements == set() and gw._sessions.current == {}
assert opener.exited == opener.entered and len(opener.exited) == 1, "retired exactly once, by the task that opened it"

second = await gw._sessions.ensure(URL)
assert second is not first and opener.opened == 2
gw._sessions.transport_failed(first, httpx.ReadError("stale")) # a report about the retired session
assert gw._sessions.retirements == set() and gw._sessions.current[URL] is second

gw._sessions.closing = True
gw._sessions.transport_failed(second, httpx.ReadError("at shutdown"))
assert gw._sessions.retirements == set(), "nothing is retired on the way down; the process lifespan closes it"
try:
first = await gw._sessions.ensure(URL)
gw._sessions.transport_failed(first, httpx.ReadError("peer went away"))
gw._sessions.transport_failed(first, httpx.ReadError("again")) # every request in flight reports; one retirement
assert len(gw._sessions.retirements) == 1
await asyncio.gather(*gw._sessions.retirements)
assert gw._sessions.retirements == set() and gw._sessions.current == {}
assert opener.exited == opener.entered and len(opener.exited) == 1, "retired exactly once, by the task that opened it"

second = await gw._sessions.ensure(URL)
assert second is not first and opener.opened == 2
gw._sessions.transport_failed(first, httpx.ReadError("stale")) # a report about the retired session
assert gw._sessions.retirements == set() and gw._sessions.current[URL] is second

gw._sessions.closing = True
gw._sessions.transport_failed(second, httpx.ReadError("at shutdown"))
assert gw._sessions.retirements == set(), "nothing is retired on the way down; the process lifespan closes it"
finally:
await gw._close_child_sessions()


@pytest.mark.asyncio
Expand Down
Loading