Skip to content

Commit 877ff93

Browse files
authored
testrunner: automatically allow parent testcase failure (#3737)
## Changes - Include logs when test is passed on retry so that it's clear it does not cause the failure. - Automatically match parent tests cases. ## Why If you have a subtest failure, parent test fails as well. Rather than requiring to specify all parent tests, we automatically allow them. Inspired by this output: ``` acceptance TestAccept/bundle/templates/default-python/combinations/classic/DATABRICKS_BUNDLE_ENGINE=direct-exp/DLT=no/NBOOK=no/PY=no failure is not allowed acceptance TestAccept/bundle/templates/default-python/combinations/classic/DATABRICKS_BUNDLE_ENGINE=direct-exp/DLT=no/NBOOK=no/PY=yes failure is not allowed acceptance TestAccept/bundle/templates/default-python/combinations/classic failure is not allowed acceptance TestAccept failure is not allowed ``` Here parent tests are 'TestAccept/bundle/templates/default-python/combinations/classic' and 'TestAccept'. So if known_failures.txt specifies "acceptance TestAccept/bundle/templates/default-python/combinations/classic/" then TestAccept would not match without this PR. If users specify "acceptance TestAccept/bundle/templates/default-python/combinations/classic/DATABRICKS_BUNDLE_ENGINE=direct-exp/DLT=no/NBOOK=no/PY=no" then neither "TestAccept" nor "TestAccept/bundle/templates/default-python/combinations/classic" would match without this PR. ## Tests Unit tests.
1 parent 8f89312 commit 877ff93

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

tools/testrunner/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ func checkFailures(config *Config, jsonFile string, originalExitCode int) int {
188188
fmt.Printf("%s %s failure is not allowed\n", result.Package, result.Test)
189189
unexpectedFailures[key] = true
190190
}
191-
} else if result.Action == "pass" {
191+
} else if result.Action == "pass" && unexpectedFailures[key] {
192+
fmt.Printf("%s %s passed on retry\n", result.Package, result.Test)
192193
// We run gotestsum with --rerun-fails, so we need to account for intermittent failures
193194
delete(unexpectedFailures, key)
194195
}
@@ -328,20 +329,20 @@ func (r ConfigRule) matches(packageName, testName string) bool {
328329

329330
// Check test pattern
330331
if r.TestPrefix {
331-
return matchesPathPrefix(testName, r.TestPattern)
332+
return matchesPathPrefix(testName, r.TestPattern) || matchesPathPrefix(r.TestPattern, testName)
332333
} else {
333-
return testName == r.TestPattern
334+
return testName == r.TestPattern || matchesPathPrefix(r.TestPattern, testName)
334335
}
335336
}
336337

337338
// matchesPathPrefix returns true if s matches pattern or starts with pattern + "/"
338339
// If pattern is empty (wildcard "*"), it matches any string
339-
func matchesPathPrefix(s, pattern string) bool {
340-
if pattern == "" {
340+
func matchesPathPrefix(s, prefix string) bool {
341+
if prefix == "" {
341342
return true
342343
}
343-
if s == pattern {
344+
if s == prefix {
344345
return true
345346
}
346-
return strings.HasPrefix(s, pattern+"/")
347+
return strings.HasPrefix(s, prefix+"/")
347348
}

tools/testrunner/main_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ func TestConfigRuleMatches(t *testing.T) {
4242
// Empty values cases
4343
{"* TestDeploy", "", "TestDeploy", true},
4444
{"bundle *", "bundle", "", true},
45+
46+
// Subtest failure results in parent test failure as well. So we allow strict prefixes to fail as well
47+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic", "acceptance", "TestAccept", true},
48+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic", "acceptance", "TestAnother", false},
49+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic", "acceptance", "TestAccept/bundle/templates/default-python/combinations/classic/x", false},
50+
51+
// pattern version
52+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic/", "acceptance", "TestAccept", true},
53+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic/", "acceptance", "TestAnother", false},
54+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic/", "acceptance", "TestAccept/bundle/templates/default-python/combinations/classic/x", true},
55+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic/", "acceptance", "TestAccept/bundle/templates/default-python/combinations/classic", true},
56+
{"acceptance TestAccept/bundle/templates/default-python/combinations/classic/", "acceptance", "TestAccept/bundle/templates/default-python/combinations", true},
4557
}
4658

4759
for _, tt := range tests {

0 commit comments

Comments
 (0)