Skip to content

Commit edcec61

Browse files
committed
Read marionette socket
1 parent e9f4fcf commit edcec61

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

test/common/bidi.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,31 +375,42 @@ async def start_bidi_session(self) -> None:
375375
for _ in range(1, 30):
376376
try:
377377
# we must keep this socket open throughout the lifetime of that session
378-
reader, self.writer_marionette = await asyncio.open_connection("127.0.0.1", marionette_port)
378+
self.reader_marionette, self.writer_marionette = await asyncio.open_connection("127.0.0.1", marionette_port)
379379
break
380380
except ConnectionRefusedError as e:
381381
log_proto.debug("waiting for firefox marionette: %s", e)
382382
await asyncio.sleep(1)
383383
else:
384384
raise WebdriverError("could not connect to firefox marionette")
385385

386-
reply = await reader.read(1024)
386+
reply = await self.reader_marionette.read(1024)
387387
if b'"marionetteProtocol":3' not in reply:
388388
raise WebdriverError(f"unexpected marionette reply: {reply.decode()}")
389389
cmd = '[0,1,"WebDriver:NewSession",{"webSocketUrl":true,"acceptInsecureCerts":true}]'
390390
self.writer_marionette.write(f"{len(cmd)}:{cmd}".encode())
391391
await self.writer_marionette.drain()
392-
reply = await reader.read(1024)
392+
reply = await self.reader_marionette.read(1024)
393393
# cut off length prefix
394394
reply = json.loads(reply[reply.index(b":") + 1:].decode())
395395
if not isinstance(reply, list) or len(reply) != 4 or not isinstance(reply[3], dict):
396396
raise WebdriverError(f"unexpected marionette session request reply: {reply!r}")
397397
log_proto.debug("marionette session request reply: %s", reply)
398398

399+
# continue to read from Marionette, in case there are any messages; we must drain the pipe
400+
self.marionette_logger: asyncio.Task = asyncio.create_task(self.log_marionette(), name="marionette_logger")
401+
399402
url = reply[3]["capabilities"]["webSocketUrl"]
400403
self.bidi_session = BidiSession(session_url=url, ws_url=url, process=driver)
401404
log_proto.debug("Established firefox session %r", self.bidi_session)
402405

406+
async def log_marionette(self) -> None:
407+
# we don't expect messages here, so log them as warnings
408+
while True:
409+
msg = await self.reader_marionette.read()
410+
log_proto.warning("marionette: %s", msg)
411+
403412
async def close_bidi_session(self) -> None:
413+
self.marionette_logger.cancel()
414+
del self.marionette_logger
404415
self.writer_marionette.close()
405416
await self.writer_marionette.wait_closed()

0 commit comments

Comments
 (0)