You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor panic and race attribution functions in Flakeguard: update regex patterns for improved accuracy, change function names to exported versions, and enhance error handling for better clarity in failure cases.
log.Warn().Str("test", testName).Str("duration_str", testDurationStr).Err(parseErr).Msg("Failed to parse duration from timed-out test line")
85
-
// If we already have a timeoutDuration, maybe use this test name anyway?
86
-
// Let's continue searching for a perfect match first. Store this as potential.
87
-
iffoundTestName=="" {
88
-
foundTestName=testName
89
-
}
74
+
// If duration parsing fails for a candidate test, immediately return a specific error
75
+
return"", true, fmt.Errorf("%w: test '%s' listed with unparseable duration '%s': %w", ErrDetectedTimeoutFailedParse, testName, testDurationStr, parseErr)
90
76
} elseiftestDuration>=timeoutDuration {
91
-
// Found the test that likely caused the timeout
92
77
log.Debug().Str("test", testName).Dur("test_duration", testDuration).Dur("timeout_duration", timeoutDuration).Msg("Attributed timeout panic via duration match")
93
-
returntestName, true, nil// Found definitive match
78
+
returntestName, true, nil// Found a valid match!
94
79
} else {
95
80
log.Debug().Str("test", testName).Dur("test_duration", testDuration).Dur("timeout_duration", timeoutDuration).Msg("Ignoring test line, duration too short for timeout")
96
81
}
97
82
}
98
83
}
99
84
100
-
// General check for test names within stack trace lines (less reliable but a fallback)
testName:=strings.TrimSpace(matchNestedTestName[1]) // Group 1 captures the core test name
104
89
if!strings.HasPrefix(testName, "Test") {
105
-
continue
90
+
continue// Should not happen with this regex, but safety check
106
91
}
107
-
// Prioritize longer, more specific names if multiple matches found?
108
-
// For now, store the first plausible one found if we haven't found one yet.
92
+
// Store the first plausible name found as a fallback
109
93
iffoundTestName=="" {
110
94
log.Debug().Str("test", testName).Str("line", output).Msg("Found potential test name in panic output")
111
95
foundTestName=testName
112
-
// Don't return yet, keep searching for more specific patterns (like timeout or log after test)
113
96
}
114
97
}
115
98
} // End loop over outputs
116
99
117
100
// Post-loop evaluation
118
101
iftimeout {
102
+
// If we reach here, timeout was detected, but NO line matched BOTH name and duration threshold.
103
+
// Return the generic attribution failure error.
104
+
varerrMsgstring
119
105
iffoundTestName!="" {
120
-
// If timeout was detected, and we found a potential test name (maybe without duration match), use it.
121
-
log.Warn().Str("test", foundTestName).Msg("Attributing timeout to test name found, but duration match was inconclusive or missing.")
122
-
returnfoundTestName, true, nil
106
+
// Include the fallback name if found, even though its duration didn't match/parse.
107
+
errMsg=fmt.Sprintf("timeout duration %s detected, found candidate test '%s' but duration did not meet threshold or failed parsing earlier", timeoutDurationStr, foundTestName)
108
+
} else {
109
+
errMsg=fmt.Sprintf("timeout duration %s detected, but no matching test found in output", timeoutDurationStr)
123
110
}
124
-
// If timeout detected but no test name found anywhere
125
-
return"", true, fmt.Errorf("%w in package context using output:\n%s", ErrDetectedTimeoutFailedAttribution, strings.Join(outputs, "\n"))
0 commit comments