Skip to content

Commit

Permalink
mantle/kola: limit testbank when doing a rerun
Browse files Browse the repository at this point in the history
Today we see an issue when trying to do a rerun when a tag was provided
because of the filtertests function logic where all the tests matching
the tag get rerun, not just the tests that failed. Let's limit the
testsBank when doing the rerun so only failed tests can possibly get
selected/run.

Fixes coreos#3041
  • Loading branch information
dustymabe committed Sep 20, 2023
1 parent 965e647 commit acf1013
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions mantle/kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,23 +855,23 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu

detectedFailedWarnTrueTests := len(getWarnTrueFailedTests(testResults.getResults())) != 0

testsToRerun := getRerunnable(testResults.getResults())
failedTests := testsToRerun
testsToRerun := getRerunnable(testsBank, testResults.getResults())
numFailedTests := len(testsToRerun)
if len(testsToRerun) > 0 && rerun {
newOutputDir := filepath.Join(outputDir, "rerun")
fmt.Printf("\n\n======== Re-running failed tests (flake detection) ========\n\n")
reRunErr := runProvidedTests(testsBank, testsToRerun, multiply, false, rerunSuccessTags, pltfrm, newOutputDir)
if reRunErr == nil && allTestsAllowRerunSuccess(testsBank, testsToRerun, rerunSuccessTags) {
runErr = nil // reset to success since all tests allowed rerun success
failedTests = []string{} // zero out the list of failed tests
reRunErr := runProvidedTests(testsToRerun, []string{"*"}, multiply, false, rerunSuccessTags, pltfrm, newOutputDir)
if reRunErr == nil && allTestsAllowRerunSuccess(testsToRerun, rerunSuccessTags) {
runErr = nil // reset to success since all tests allowed rerun success
numFailedTests = 0 // zero out the tally of failed tests
} else {
runErr = reRunErr
}

}

// Return ErrWarnOnTestFail when ONLY tests with warn:true feature failed
if detectedFailedWarnTrueTests && len(failedTests) == 0 {
if detectedFailedWarnTrueTests && numFailedTests == 0 {
return ErrWarnOnTestFail
} else {
return runErr
Expand All @@ -895,7 +895,7 @@ func getWarnTrueFailedTests(tests []*harness.H) []string {
return warnTrueFailedTests
}

func allTestsAllowRerunSuccess(testsBank map[string]*register.Test, testsToRerun, rerunSuccessTags []string) bool {
func allTestsAllowRerunSuccess(testsToRerun map[string]*register.Test, rerunSuccessTags []string) bool {
// Always consider the special AllowRerunSuccessTag that is added
// by the test harness in some failure scenarios.
rerunSuccessTags = append(rerunSuccessTags, AllowRerunSuccessTag)
Expand All @@ -913,7 +913,7 @@ func allTestsAllowRerunSuccess(testsBank map[string]*register.Test, testsToRerun
// allow rerun success then just exit early.
for _, test := range testsToRerun {
testAllowsRerunSuccess := false
for _, tag := range testsBank[test].Tags {
for _, tag := range test.Tags {
if rerunSuccessTagMap[tag] {
testAllowsRerunSuccess = true
}
Expand Down Expand Up @@ -973,20 +973,30 @@ func IsWarningOnFailure(testName string) bool {
return false
}

func getRerunnable(tests []*harness.H) []string {
var testsToRerun []string
for _, h := range tests {
func getRerunnable(testsBank map[string]*register.Test, testResults []*harness.H) map[string]*register.Test {
// First get the names of the tests that need to rerun
var testNamesToRerun []string
for _, h := range testResults {
// The current nonexclusive test wrapper would have all non-exclusive tests.
// We would add all those tests for rerunning if none of the non-exclusive
// subtests start due to some initial failure.
if nonexclusiveWrapperMatch.MatchString(h.Name()) && !h.GetNonExclusiveTestStarted() {
if h.Failed() {
testsToRerun = append(testsToRerun, h.Subtests()...)
testNamesToRerun = append(testNamesToRerun, h.Subtests()...)
}
} else {
name, isRerunnable := GetRerunnableTestName(h.Name())
if h.Failed() && isRerunnable {
testsToRerun = append(testsToRerun, name)
testNamesToRerun = append(testNamesToRerun, name)
}
}
}
// Then convert the list of names into a list of a register.Test objects
testsToRerun := make(map[string]*register.Test)
for name, t := range testsBank {
for _, rerun := range testNamesToRerun {
if name == rerun {
testsToRerun[name] = t
}
}
}
Expand Down

0 comments on commit acf1013

Please sign in to comment.