-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flakeguard: Add cmds to aggregate test results and improve memory eff…
…iciency by save test outputs to files (#1336)
- Loading branch information
Showing
7 changed files
with
480 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var AggregateAllCmd = &cobra.Command{ | ||
Use: "aggregate-all", | ||
Short: "Aggregate all test results and output them to a file", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
resultsFolderPath, _ := cmd.Flags().GetString("results-path") | ||
outputPath, _ := cmd.Flags().GetString("output-json") | ||
|
||
// Aggregate all test results | ||
allResults, err := reports.AggregateTestResults(resultsFolderPath) | ||
if err != nil { | ||
log.Fatalf("Error aggregating results: %v", err) | ||
} | ||
|
||
// Output all results to JSON file | ||
if outputPath != "" && len(allResults) > 0 { | ||
if err := saveResults(outputPath, allResults); err != nil { | ||
log.Fatalf("Error writing aggregated results to file: %v", err) | ||
} | ||
fmt.Printf("Aggregated test results saved to %s\n", outputPath) | ||
} else { | ||
fmt.Println("No test results found.") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
AggregateAllCmd.Flags().String("results-path", "testresult/", "Path to the folder containing JSON test result files") | ||
AggregateAllCmd.Flags().String("output-json", "all_tests.json", "Path to output the aggregated test results in JSON format") | ||
} |
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,60 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var AggregateFailedCmd = &cobra.Command{ | ||
Use: "aggregate-failed", | ||
Short: "Aggregate all test results, then filter and output only failed tests based on a threshold", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
resultsFolderPath, _ := cmd.Flags().GetString("results-path") | ||
outputPath, _ := cmd.Flags().GetString("output-json") | ||
threshold, _ := cmd.Flags().GetFloat64("threshold") | ||
|
||
// Aggregate all test results | ||
allResults, err := reports.AggregateTestResults(resultsFolderPath) | ||
if err != nil { | ||
log.Fatalf("Error aggregating results: %v", err) | ||
} | ||
|
||
// Filter to only include failed tests based on threshold | ||
var failedResults []reports.TestResult | ||
for _, result := range allResults { | ||
if result.PassRatio < threshold && !result.Skipped { | ||
failedResults = append(failedResults, result) | ||
} | ||
} | ||
|
||
// Output failed results to JSON file | ||
if outputPath != "" && len(failedResults) > 0 { | ||
if err := saveResults(outputPath, failedResults); err != nil { | ||
log.Fatalf("Error writing failed results to file: %v", err) | ||
} | ||
fmt.Printf("Filtered failed test results saved to %s\n", outputPath) | ||
} else { | ||
fmt.Println("No failed tests found based on the specified threshold.") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
AggregateFailedCmd.Flags().String("results-path", "testresult/", "Path to the folder containing JSON test result files") | ||
AggregateFailedCmd.Flags().String("output-json", "failed_tests.json", "Path to output the filtered failed test results in JSON format") | ||
AggregateFailedCmd.Flags().Float64("threshold", 0.8, "Threshold for considering a test as failed") | ||
} | ||
|
||
// Helper function to save results to JSON file | ||
func saveResults(filePath string, results []reports.TestResult) error { | ||
data, err := json.MarshalIndent(results, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("error marshaling results: %v", err) | ||
} | ||
return os.WriteFile(filePath, data, 0644) | ||
} |
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
Oops, something went wrong.