Skip to content
Merged
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
40 changes: 27 additions & 13 deletions tests/unit/admin_console/test_host_agent_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from artemis.runtime.host_protocol import CONTRACT

HOST = {"Host": "localhost"}
# Only stops a stalled wire test from hanging; a tight deadline on loopback I/O measures how busy the host is (CHE-2010).
STALL_BOUND = 60


def test_agent_unenroll_revokes_only_authenticated_identity(admin):
Expand Down Expand Up @@ -259,12 +261,20 @@ async def startup(self, sockets=None):
server = ReadyServer(config)
task = asyncio.create_task(server.serve(sockets=[listener]))
try:
await asyncio.wait_for(ready.wait(), 5)
ready_wait = asyncio.ensure_future(ready.wait())
await asyncio.wait(
{ready_wait, task}, timeout=STALL_BOUND, return_when=asyncio.FIRST_COMPLETED
)
ready_wait.cancel()
if not ready.is_set():
if task.done():
await task # surface the server's own startup error
raise AssertionError("wire server never became ready")
yield f"localhost:{port}", tunnels, clock, outcomes, lost
finally:
server.should_exit = True
try:
await asyncio.wait_for(task, 5)
await asyncio.wait_for(task, STALL_BOUND)
finally:
await tunnels.close()
listener.close()
Expand All @@ -286,7 +296,7 @@ async def test_real_host_socket_close_enters_grace_and_expires_once(admin, wire_
await ws.close()
else:
ws.transport.abort()
await asyncio.wait_for(lost.wait(), 1)
await asyncio.wait_for(lost.wait(), STALL_BOUND)
assert tunnels.reconnecting(host_id) == 130
assert outcomes == []
clock["now"] = 130
Expand Down Expand Up @@ -325,14 +335,14 @@ async def test_agent_rejects_oversize_host_message_with_bridge_transport_cap(
assert connected["type"] == "connected", connected
tunnels.bind_run(host_id, "run")
await ws.send(payload)
assert json.loads(await asyncio.wait_for(ws.recv(), 2)) == {
assert json.loads(await asyncio.wait_for(ws.recv(), STALL_BOUND)) == {
"type": "error",
"code": "bad_frame",
}
with pytest.raises(ConnectionClosedError) as closed:
await asyncio.wait_for(ws.recv(), 2)
await asyncio.wait_for(ws.recv(), STALL_BOUND)
assert closed.value.rcvd.code == 4400
await asyncio.wait_for(lost.wait(), 1)
await asyncio.wait_for(lost.wait(), STALL_BOUND)
assert decode.call_count == (1 if isinstance(payload, bytes) else 2)
assert frame_decode.call_count == (1 if isinstance(payload, bytes) else 0)

Expand Down Expand Up @@ -363,20 +373,24 @@ async def fake_adb(*arguments):
max_size=MAX_ADB_PACKET_BYTES,
compression=None,
) as ws:
leased = json.loads(await asyncio.wait_for(ws.recv(), 2))
leased = json.loads(await asyncio.wait_for(ws.recv(), STALL_BOUND))
assert leased["type"] == "session_leased"
assert json.loads(await asyncio.wait_for(ws.recv(), 2))["type"] == "device_attached"
assert (
json.loads(await asyncio.wait_for(ws.recv(), STALL_BOUND))["type"] == "device_attached"
)
peer_reader, peer_writer = await asyncio.open_connection(
leased["listener"]["host"], leased["listener"]["port"]
)
try:
await ws.send(packet)
assert await asyncio.wait_for(peer_reader.readexactly(len(packet)), 2) == packet
assert (
await asyncio.wait_for(peer_reader.readexactly(len(packet)), STALL_BOUND) == packet
)
peer_writer.write(packet)
await peer_writer.drain()
assert await asyncio.wait_for(ws.recv(), 2) == packet
assert await asyncio.wait_for(ws.recv(), STALL_BOUND) == packet
await ws.send("close")
await asyncio.wait_for(ws.wait_closed(), 2)
await asyncio.wait_for(ws.wait_closed(), STALL_BOUND)
finally:
await bridge.revoke(leased["session_id"])
peer_writer.close()
Expand All @@ -396,9 +410,9 @@ async def test_uvicorn_bounds_messages_at_the_bridge_limit(admin, wire_server):
tunnels.bind_run(host_id, "run")
await ws.send(bytes(MAX_ADB_PACKET_BYTES + 1))
with pytest.raises(ConnectionClosedError) as closed:
await asyncio.wait_for(ws.recv(), 2)
await asyncio.wait_for(ws.recv(), STALL_BOUND)
assert closed.value.rcvd.code == 1009
await asyncio.wait_for(lost.wait(), 1)
await asyncio.wait_for(lost.wait(), STALL_BOUND)


# -- flag ---------------------------------------------------------------
Expand Down
Loading