Skip to content

Commit e0f2cac

Browse files
committed
cmd/watchflakes: coalesce a package-level failure to a test failure in the same package
Recently we added reporting package-level failures (that is not associated to a specific test) to LUCI. In some cases, e.g. a test timeout could also cause a package-level failure. E.g. https://ci.chromium.org/b/8745232168515795905 . Currently watchflakes reports them as two issues. But they are the same cause. This CL changes it to combine them, when there is a package-level failure and also a test failure in the same package. Also update splitTestID to handle package-level failure. If it cannot split, treat the whole TestID as package, not the test. Fixes golang/go#68597. Change-Id: I0679a0345194589e84b351ea7519b2d4da2731e3 Reviewed-on: https://go-review.googlesource.com/c/build/+/601436 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 6f08d2f commit e0f2cac

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

cmd/watchflakes/luci.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ func splitTestID(testid string) (string, string) {
538538
return pkg, sep[1:] + test // add back "Test" prefix (without ".")
539539
}
540540
}
541-
return "", testid
541+
// Maybe a package-level target (e.g. build failure).
542+
return testid, ""
542543
}
543544

544545
func buildURL(buildID int64) string { // keep in sync with buildUrlRE in github.go

cmd/watchflakes/main.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,20 @@ func snippet(log string) string {
597597
func coalesceFailures(fs []*Failure) []*Failure {
598598
var res []*Failure
599599
// A subtest fail may cause the parent test to fail, combine them.
600+
// So is a test failure causing package-level failure.
600601
var cur *Failure
601602
for _, f := range fs {
602-
if cur != nil && strings.HasPrefix(f.TestID, cur.TestID+"/") {
603-
// f is a subtest of cur. Consume cur, replace with f.
604-
res[len(res)-1] = f
605-
cur = f
606-
continue
603+
if cur != nil {
604+
cpkg, ctst := splitTestID(cur.TestID)
605+
if (ctst == "" && strings.HasPrefix(f.TestID, cpkg+".")) ||
606+
strings.HasPrefix(f.TestID, cur.TestID+"/") {
607+
// 1. cur is a package-level failure, and f is a test in that package
608+
// 2. f is a subtest of cur.
609+
// In either case, consume cur, replace with f.
610+
res[len(res)-1] = f
611+
cur = f
612+
continue
613+
}
607614
}
608615
cur = f
609616
res = append(res, f)
@@ -619,10 +626,21 @@ func coalesceFailures(fs []*Failure) []*Failure {
619626
return strings.Contains(f.LogText, "--- FAIL") &&
620627
(!strings.Contains(last.LogText, "--- FAIL") || len(f.LogText) > len(last.LogText))
621628
}
629+
siblingSubtests := func(f, last *Failure) bool {
630+
pkg, tst := splitTestID(f.TestID)
631+
pkg2, tst2 := splitTestID(last.TestID)
632+
if pkg != pkg2 {
633+
return false
634+
}
635+
par, _, ok := strings.Cut(tst, "/")
636+
par2, _, ok2 := strings.Cut(tst2, "/")
637+
return ok && ok2 && par == par2
638+
}
622639
cur = nil
640+
fs = res
623641
res = fs[:0]
624642
for _, f := range fs {
625-
if cur != nil && strings.HasPrefix(f.TestID, cur.TestID+"/") {
643+
if cur != nil && siblingSubtests(f, cur) {
626644
if moreLikelyUseful(f, res[len(res)-1]) {
627645
res[len(res)-1] = f
628646
}

0 commit comments

Comments
 (0)