Skip to content

Commit

Permalink
test: fix serial console is not closed exception
Browse files Browse the repository at this point in the history
  • Loading branch information
squirrelsc authored and LiliDeng committed Jun 26, 2024
1 parent 9581d80 commit cf432ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lisa/features/serial_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@ def read(self) -> str:

def write(self, data: str) -> None:
raise NotImplementedError

def close(self) -> None:
# it's not required to implement close method.
pass
6 changes: 6 additions & 0 deletions lisa/sut_orchestrator/azure/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ def read(self) -> str:
self._get_connection()
raise e

def close(self) -> None:
if self._ws is not None:
self._log.debug("Closing connection to serial console")
self._get_event_loop().run_until_complete(self._ws.close())
self._ws = None

def _get_event_loop(self) -> asyncio.AbstractEventLoop:
# create asyncio loop if it doesn't exist
try:
Expand Down
4 changes: 3 additions & 1 deletion microsoft/testsuites/core/serial_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ def verify_serial_console(self, log: Logger, node: Node) -> None:
serial_console = node.features[SerialConsole]

# retry to read serial console output, because it may not be ready
for _ in range(180):
for i in range(180):
_ = serial_console.read()
serial_console.write(command)
output = serial_console.read()

# check if the output contains the command
if command in output:
serial_console.close()
log.debug(f"called {i} times, get output from serial console: {output}")
break

# sleep for 1 second
Expand Down

0 comments on commit cf432ea

Please sign in to comment.