Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: junit retry regression for xcuitests in rdc #887

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions internal/saucecloud/retry/junitretrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func setClassesToRetry(opt *job.StartOptions, testcases []junit.TestCase) {
}

if opt.Framework == xcuitest.Kind {
tests := getFailedXCUITests(testcases)
tests := getFailedXCUITests(testcases, opt.RealDevice)

// RDC and VDC API filter use different fields for test filtering.
if opt.RealDevice {
Expand Down Expand Up @@ -89,11 +89,11 @@ func (b *JunitRetrier) Retry(jobOpts chan<- job.StartOptions, opt job.StartOptio
// getFailedXCUITests returns a list of failed XCUITest tests from the given
// test cases. The format is "<className>/<testMethodName>", with the test
// method name being optional.
func getFailedXCUITests(testCases []junit.TestCase) []string {
func getFailedXCUITests(testCases []junit.TestCase, rdc bool) []string {
classes := map[string]bool{}
for _, tc := range testCases {
if tc.Error != nil || tc.Failure != nil {
className := normalizeXCUITestClassName(tc.ClassName)
className := conformXCUITestClassName(tc.ClassName, rdc)
if tc.Name != "" {
classes[fmt.Sprintf("%s/%s", className, tc.Name)] = true
} else {
Expand All @@ -104,12 +104,18 @@ func getFailedXCUITests(testCases []junit.TestCase) []string {
return maps.Keys(classes)
}

// normalizeXCUITestClassName normalizes the class name of an XCUITest. The
// class name within the platform generated JUnit XML file can be dot-separated,
// but our platform API expects a slash-separated class name. The platform is
// unfortunately not consistent in this regard and is not in full control of the
// generated JUnit XML file, hence we reconcile the two here.
func normalizeXCUITestClassName(name string) string {
// conformXCUITestClassName conforms the class name of an XCUITest to either
// RDC or VMD. The class name within the platform generated JUnit XML file can
// be dot-separated, but unlike RDC, VMD expects a slash-separated class name.
// The platform is unfortunately not consistent in this regard and is not in
// full control of the generated JUnit XML file.
// If the test is run on RDC, the class name is not modified and returned as is.
// If the test is run on VMD, the class name is converted to a slash-separated.
func conformXCUITestClassName(name string, rdc bool) string {
if rdc {
return name
}

items := strings.Split(name, ".")
if len(items) == 1 {
return name
Expand Down
34 changes: 26 additions & 8 deletions internal/saucecloud/retry/junitretrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestAppsRetrier_Retry(t *testing.T) {
Framework: xcuitest.Kind,
DisplayName: "Dummy Test",
TestOptions: map[string]interface{}{},
TestsToRun: []string{"Demo/Class1/demoTest"},
TestsToRun: []string{"Demo.Class1/demoTest"},
SmartRetry: job.SmartRetry{
FailedOnly: true,
},
Expand Down Expand Up @@ -377,31 +377,49 @@ func TestAppsRetrier_Retry(t *testing.T) {
func Test_normalizeXCUITestClassName(t *testing.T) {
type args struct {
name string
rdc bool
}
tests := []struct {
name string
args args
want string
}{
{
name: "needs normalization",
args: args{name: "DemoAppTests.ClassyTest"},
name: "dot separated is not VMD conform",
args: args{
name: "DemoAppTests.ClassyTest",
rdc: false,
},
want: "DemoAppTests/ClassyTest",
},
{
name: "already normalized",
args: args{name: "DemoAppTests/ClassyTest"},
name: "already VMD conform with slashes",
args: args{
name: "DemoAppTests/ClassyTest",
rdc: false,
},
want: "DemoAppTests/ClassyTest",
},
{
name: "nothing to normalize",
args: args{name: "DemoAppTests"},
name: "already VMD conform without separators",
args: args{
name: "DemoAppTests",
rdc: false,
},
want: "DemoAppTests",
},
{
name: "already RDC conform",
args: args{
name: "DemoAppTests.ClassyTest",
rdc: true,
},
want: "DemoAppTests.ClassyTest",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, normalizeXCUITestClassName(tt.args.name), "normalizeXCUITestClassName(%v)", tt.args.name)
assert.Equalf(t, tt.want, conformXCUITestClassName(tt.args.name, tt.args.rdc), "conformXCUITestClassName(%v)", tt.args.name)
})
}
}
Loading