diff --git a/eng/scripts/dispatch_checks.py b/eng/scripts/dispatch_checks.py index d9196d881337..b76cd188b97f 100644 --- a/eng/scripts/dispatch_checks.py +++ b/eng/scripts/dispatch_checks.py @@ -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") diff --git a/eng/tools/azure-sdk-tools/tests/test_dispatch_checks.py b/eng/tools/azure-sdk-tools/tests/test_dispatch_checks.py index c286d38c2e68..bbaeab141af8 100644 --- a/eng/tools/azure-sdk-tools/tests/test_dispatch_checks.py +++ b/eng/tools/azure-sdk-tools/tests/test_dispatch_checks.py @@ -1,3 +1,5 @@ +import asyncio +from io import StringIO import os import sys from types import SimpleNamespace @@ -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(): @@ -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"