-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enables selection and execution of specific e2e benchmark tests (…
…#3595) Closes #3588 Now, you can pass the test name as an arument: ``` go run ./test/e2e/benchmark TwoNodeSimple -v ``` And at the end you will see ``` test-e2e-benchmark2024/06/18 15:44:38 --- ✅ PASS: TwoNodeSimple ```
- Loading branch information
Showing
2 changed files
with
64 additions
and
10 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,61 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
logger := log.New(os.Stdout, "test-e2e-benchmark", log.LstdFlags) | ||
|
||
tests := []Test{ | ||
{"TwoNodeSimple", TwoNodeSimple}, | ||
} | ||
|
||
// check the test name passed as an argument and run it | ||
specificTestFound := false | ||
for _, arg := range os.Args[1:] { | ||
for _, test := range tests { | ||
if test.Name == arg { | ||
runTest(logger, test) | ||
specificTestFound = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
if !specificTestFound { | ||
logger.Println("No particular test specified. Running all tests.") | ||
logger.Println("go run ./test/e2e/benchmark <test_name> to run a specific test") | ||
logger.Printf("Valid tests are: %s\n\n", getTestNames(tests)) | ||
// if no specific test is passed, run all tests | ||
for _, test := range tests { | ||
runTest(logger, test) | ||
} | ||
} | ||
} | ||
|
||
type TestFunc func(*log.Logger) error | ||
|
||
type Test struct { | ||
Name string | ||
Func TestFunc | ||
} | ||
|
||
func runTest(logger *log.Logger, test Test) { | ||
logger.Printf("=== RUN %s", test.Name) | ||
err := test.Func(logger) | ||
if err != nil { | ||
logger.Fatalf("--- ERROR %s: %v", test.Name, err) | ||
} | ||
logger.Printf("--- ✅ PASS: %s \n\n", test.Name) | ||
} | ||
|
||
func getTestNames(tests []Test) string { | ||
testNames := make([]string, 0, len(tests)) | ||
for _, test := range tests { | ||
testNames = append(testNames, test.Name) | ||
} | ||
return strings.Join(testNames, ", ") | ||
} |
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