-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
if you retry flaky tests and the last attempt succeeded, the step sho…
…uld succeed (#95) * if you retry flaky tests and the last attempt succeeded, the step should succeed * distinguish based on dimension * fix npe? * remove log line * debug logging on dimension success * more logging * fix last step calc * remove logging * restructure for simplicity to understand * missing completion time debugging * more debugging * stop caring about completion time * move to package * use testify * rename package to not conflict with existing bitrise mores * rename package * well i guess i learned a little bout go * bitrise syntax * bitrise syntax
- Loading branch information
1 parent
f6fabdd
commit 4fdef16
Showing
59 changed files
with
23,951 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package resultprocessing | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
toolresults "google.golang.org/api/toolresults/v1beta3" | ||
) | ||
|
||
// GetSuccessOfExecution ... | ||
// Given multiple steps, return whether we can consider the overall execution successful | ||
// To do this, step executions are grouped by dimension (aka what device they ran on) | ||
// and each dimension must have a successful execution | ||
func GetSuccessOfExecution(steps []*toolresults.Step) (bool, error) { | ||
outcomeByDimension, err := getOutcomeByDimension(steps) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
for _, outcome := range outcomeByDimension { | ||
if outcome.Summary != "success" { | ||
return false, nil | ||
} | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
func getOutcomeByDimension(steps []*toolresults.Step) (map[string]*toolresults.Outcome, error) { | ||
groupedByDimension := make(map[string]*toolresults.Outcome) | ||
for _, step := range steps { | ||
key, err := json.Marshal(step.DimensionValue) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if key != nil { | ||
dimensionStr := string(key) | ||
if groupedByDimension[dimensionStr] == nil || groupedByDimension[dimensionStr].Summary != "success" { | ||
groupedByDimension[dimensionStr] = step.Outcome | ||
} | ||
} | ||
} | ||
|
||
return groupedByDimension, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package resultprocessing | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
toolresults "google.golang.org/api/toolresults/v1beta3" | ||
) | ||
|
||
func TestGetSuccessOfExecution_AllSucceed(t *testing.T) { | ||
steps := []*toolresults.Step{ | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
Outcome: &toolresults.Outcome{Summary: "success"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "ios"}}, | ||
Outcome: &toolresults.Outcome{Summary: "success"}, | ||
}, | ||
} | ||
|
||
isSuccess, err := GetSuccessOfExecution(steps) | ||
require.NoError(t, err) | ||
require.True(t, isSuccess) | ||
} | ||
|
||
func TestGetSuccessOfExecution_FirstFailThenSucceed(t *testing.T) { | ||
steps := []*toolresults.Step{ | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
Outcome: &toolresults.Outcome{Summary: "failure"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
Outcome: &toolresults.Outcome{Summary: "success"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "ios"}}, | ||
Outcome: &toolresults.Outcome{Summary: "success"}, | ||
}, | ||
} | ||
|
||
isSuccess, err := GetSuccessOfExecution(steps) | ||
require.NoError(t, err) | ||
require.True(t, isSuccess) | ||
} | ||
|
||
func TestGetSuccessOfExecution_FailDifferentDimension(t *testing.T) { | ||
steps := []*toolresults.Step{ | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
Outcome: &toolresults.Outcome{Summary: "failure"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
Outcome: &toolresults.Outcome{Summary: "success"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "ios"}}, | ||
Outcome: &toolresults.Outcome{Summary: "failure"}, | ||
}, | ||
} | ||
|
||
isSuccess, err := GetSuccessOfExecution(steps) | ||
require.NoError(t, err) | ||
require.False(t, isSuccess) | ||
} | ||
|
||
func TestGetSuccessOfExecution_FailForDimension(t *testing.T) { | ||
steps := []*toolresults.Step{ | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
CompletionTime: &toolresults.Timestamp{Seconds: 1}, | ||
Outcome: &toolresults.Outcome{Summary: "failure"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "ios"}}, | ||
CompletionTime: &toolresults.Timestamp{Seconds: 2}, | ||
Outcome: &toolresults.Outcome{Summary: "success"}, | ||
}, | ||
} | ||
|
||
isSuccess, err := GetSuccessOfExecution(steps) | ||
require.NoError(t, err) | ||
require.False(t, isSuccess) | ||
} | ||
|
||
func TestGetSuccessOfExecution_FailBothDimensions(t *testing.T) { | ||
steps := []*toolresults.Step{ | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "android"}}, | ||
Outcome: &toolresults.Outcome{Summary: "failure"}, | ||
}, | ||
{ | ||
DimensionValue: []*toolresults.StepDimensionValueEntry{{Key: "os", Value: "ios"}}, | ||
Outcome: &toolresults.Outcome{Summary: "failure"}, | ||
}, | ||
} | ||
|
||
isSuccess, err := GetSuccessOfExecution(steps) | ||
require.NoError(t, err) | ||
require.False(t, isSuccess) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.