Skip to content

Commit 5479de1

Browse files
scottcaometa-codesync[bot]
authored andcommitted
Fix flaky buck2 core golden tests by stripping spurious glog lines
Summary: Three buck2 core tests were intermittently failing because C++ libraries linked into the buck2 binary (and the tools it spawns) emit a glog-format INFO line to stderr during process init, e.g. `I0623 15:40:41.926481 128942 Hash.cpp:327] tiHash seed: 12824087ull` (from `ti/common/utils/Hash.cpp`). Whether and when these lines appear in captured stderr varies between runs, so they leak non-deterministically into the output that golden tests compare against: - `test_errors.py::test_package_listing_errors` - `test_formatting.py::test_bxl_with_stacktrace` - `test_error_categorization.py::test_init_data_timeout` The line uses the standard glog prefix (`[WIEF]MMDD HH:MM:SS.dddddd`), which is distinct from buck2's own tracing-subscriber `[<TIMESTAMP>]` format, so it can be filtered safely. This adds a shared `strip_glog_lines` helper to `golden.py` that drops whole lines carrying the glog marker while preserving all other newlines (so callers' trailing/blank-line structure is unchanged), and applies it in the central `sanitize_stderr` plus the two tests that use custom sanitizers. The existing copy-pasted glog filter in `test_oom_detection.py` is consolidated onto the shared helper. The marker is matched anywhere in the line so indented occurrences (e.g. when nested inside an embedded daemon stderr block, as in `test_init_data_timeout`) are also stripped. ___ Differential Revision: D109498020 fbshipit-source-id: 463221a583984f1fdf3ef40e234c889de325bc85
1 parent 5f01c59 commit 5479de1

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

tests/core/errors/test_errors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from buck2.tests.e2e_util.api.buck import Buck
1313
from buck2.tests.e2e_util.asserts import expect_failure
1414
from buck2.tests.e2e_util.buck_workspace import buck_test, env
15-
from buck2.tests.e2e_util.helper.golden import golden
15+
from buck2.tests.e2e_util.helper.golden import golden, strip_glog_lines
1616

1717

1818
@buck_test()
@@ -72,7 +72,10 @@ async def test_package_listing_errors(buck: Buck) -> None:
7272
)
7373
outs.append(stripped_stderr)
7474

75-
golden(output="\n\n\n".join(outs), rel_path="package_listing/expected.golden.out")
75+
golden(
76+
output=strip_glog_lines("\n\n\n".join(outs)),
77+
rel_path="package_listing/expected.golden.out",
78+
)
7679

7780

7881
@buck_test(

tests/core/errors/test_formatting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from buck2.tests.e2e_util.api.buck import Buck
1515
from buck2.tests.e2e_util.asserts import expect_failure
1616
from buck2.tests.e2e_util.buck_workspace import buck_test
17-
from buck2.tests.e2e_util.helper.golden import golden
17+
from buck2.tests.e2e_util.helper.golden import golden, strip_glog_lines
1818

1919

2020
def _sanitize(s: str) -> str:
21+
s = strip_glog_lines(s)
2122
# Remove configuration hashes
2223
s = re.sub(r"\b[0-9a-f]{16}\b", "<HASH>", s)
2324
# And action digests

tests/e2e_util/helper/golden.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,25 @@ def sanitize_hashes(s: str) -> str:
169169
return re.sub(r"\b[0-9a-f]{40}:[0-9]{1,3}\b", "<DIGEST>", s)
170170

171171

172+
# C++ libraries linked into buck2 (and the tools it spawns) can emit glog-format
173+
# lines such as `I0623 15:40:41.926481 128942 Hash.cpp:327] tiHash seed: ...ull`
174+
# to stderr during process init. Their timestamps, PIDs, and source locations
175+
# vary between runs, so they leak non-deterministically into captured stderr and
176+
# must be dropped before comparing against goldens. The marker may be indented
177+
# (e.g. when nested inside an embedded daemon stderr block), so we match it
178+
# anywhere in the line.
179+
_GLOG_LINE_RE = re.compile(r".*[WIEF]\d{4} \d{2}:\d{2}:\d{2}\.\d{6}.*\n?")
180+
181+
182+
def strip_glog_lines(s: str) -> str:
183+
# Drops whole matching lines (leading indentation and trailing newline
184+
# included) while leaving every other newline intact, so callers' trailing
185+
# and blank-line structure is preserved.
186+
return _GLOG_LINE_RE.sub("", s)
187+
188+
172189
def sanitize_stderr(s: str) -> str:
190+
s = strip_glog_lines(s)
173191
# Remove all timestamps
174192
s = re.sub(r"\[.{29}\]", "[<TIMESTAMP>]", s)
175193
# Remove all UUIDs

0 commit comments

Comments
 (0)