Skip to content
Draft
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
7 changes: 6 additions & 1 deletion eng/scripts/dispatch_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ async def _pump(stream: Optional[asyncio.StreamReader], sink: IO[str]) -> str:
return ""
chunks: List[str] = []
while True:
line_b = await stream.readline()
try:
line_b = await stream.readline()
except (ValueError, asyncio.LimitOverrunError):
sink.write(prefix + "[suppressed oversized log line]\n")
sink.flush()
continue
if not line_b:
break
line = line_b.decode(errors="replace")
Expand Down
36 changes: 35 additions & 1 deletion eng/tools/azure-sdk-tools/tests/test_dispatch_checks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio
from io import StringIO
import os
import sys
from types import SimpleNamespace
Expand All @@ -10,7 +12,7 @@
if REPO_ROOT not in sys.path:
sys.path.insert(0, REPO_ROOT)

from eng.scripts.dispatch_checks import get_check_dest_dir
from eng.scripts.dispatch_checks import _tee_stream, get_check_dest_dir


def test_apistub_dest_dir_uses_package_subdirectory():
Expand Down Expand Up @@ -45,3 +47,35 @@ def test_empty_dest_dir_is_unchanged():

assert result is None
parsed_setup.assert_not_called()


def test_tee_stream_suppresses_oversized_line():
class Stream:
def __init__(self):
self.lines = [asyncio.LimitOverrunError("line is too long", 0), b"next line\n", b""]

async def readline(self):
line = self.lines.pop(0)
if isinstance(line, Exception):
raise line
return line

class Process:
def __init__(self):
self.stdout = Stream()
self.stderr = Stream()

async def wait(self):
pass

stdout_sink = StringIO()
stderr_sink = StringIO()
with patch("eng.scripts.dispatch_checks.sys.stdout", stdout_sink), patch(
"eng.scripts.dispatch_checks.sys.stderr", stderr_sink
):
stdout, stderr = asyncio.run(_tee_stream(Process(), "/tmp/package", "check"))

assert stdout == "next line\n"
assert stderr == "next line\n"
assert stdout_sink.getvalue() == "[package :: check] [suppressed oversized log line]\n[package :: check] next line\n"
assert stderr_sink.getvalue() == "[package :: check] [suppressed oversized log line]\n[package :: check] next line\n"
Loading