mtest: do not process zero byte reads in read_decode()

AsyncIO.StreamReader.readuntil() occasionally raises IncompleteRead
exception before a byte of data has been read. Do not process the "read"
data in those cases.
This commit is contained in:
Hemmo Nieminen 2022-02-18 00:00:00 +02:00 committed by Eli Schwartz
parent 657a6eeb81
commit e8a3f4d38c
1 changed files with 5 additions and 4 deletions

View File

@ -1118,10 +1118,11 @@ async def read_decode(reader: asyncio.StreamReader, console_mode: ConsoleUser) -
line_bytes = e.partial
except asyncio.LimitOverrunError as e:
line_bytes = await reader.readexactly(e.consumed)
line = decode(line_bytes)
stdo_lines.append(line)
if console_mode is ConsoleUser.STDOUT:
print(line, end='', flush=True)
if line_bytes:
line = decode(line_bytes)
stdo_lines.append(line)
if console_mode is ConsoleUser.STDOUT:
print(line, end='', flush=True)
return ''.join(stdo_lines)
except asyncio.CancelledError:
return ''.join(stdo_lines)