Skip to content

Commit 2dbac3e

Browse files
committed
Handle panic in flakeguard tests
1 parent 7987e78 commit 2dbac3e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tools/flakeguard/reports/reports.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
type TestResult struct {
1414
TestName string
1515
TestPackage string
16+
Panicked bool // Indicates a test-level panic
17+
PackagePanicked bool // Indicates a package-level panic
1618
PassRatio float64 // Pass ratio in decimal format like 0.5
1719
PassRatioPercentage string // Pass ratio in percentage format like "50%"
1820
Skipped bool // Indicates if the test was skipped

tools/flakeguard/runner/runner.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import (
88
"log"
99
"os"
1010
"os/exec"
11+
"regexp"
1112
"strings"
1213

1314
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
1415
)
1516

17+
var (
18+
panicRe = regexp.MustCompile(`^panic:`)
19+
)
20+
1621
type Runner struct {
1722
ProjectPath string // Path to the Go project directory.
1823
Verbose bool // If true, provides detailed logging.
@@ -140,6 +145,18 @@ func parseTestResults(filePaths []string) ([]reports.TestResult, error) {
140145
result.Durations = append(result.Durations, entry.Elapsed)
141146
case "output":
142147
result.Outputs = append(result.Outputs, entry.Output)
148+
if panicRe.MatchString(entry.Output) {
149+
if entry.Test != "" {
150+
// Test-level panic: treat it as a failing test
151+
result.Panicked = true
152+
} else {
153+
// Package-level panic
154+
result.PackagePanicked = true
155+
}
156+
result.PassRatio = (result.PassRatio * float64(result.Runs-1)) / float64(result.Runs)
157+
result.PassRatioPercentage = fmt.Sprintf("%.0f%%", result.PassRatio*100)
158+
result.Durations = append(result.Durations, entry.Elapsed)
159+
}
143160
case "fail":
144161
result.PassRatio = (result.PassRatio * float64(result.Runs-1)) / float64(result.Runs)
145162
result.PassRatioPercentage = fmt.Sprintf("%.0f%%", result.PassRatio*100)

0 commit comments

Comments
 (0)