Skip to content

Commit

Permalink
Revert "Resolve the requested changes"
Browse files Browse the repository at this point in the history
This reverts commit 4ad64eb.
  • Loading branch information
ShubhamRasal committed Mar 1, 2023
1 parent 4ad64eb commit d32c9c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
- name: Integration Tests
env:
GH_ACTION: true
GH_ACTION_RETRIES: "3"
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
chmod +x run.sh
Expand Down
57 changes: 16 additions & 41 deletions v2/cmd/integration-test/integration-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"os"
"strconv"
"strings"

"github.com/logrusorgru/aurora"
Expand All @@ -13,10 +12,9 @@ import (
)

var (
debug = os.Getenv("DEBUG") == "true"
githubAction = os.Getenv("GH_ACTION") == "true"
githubActionRetries = os.Getenv("GH_ACTION_RETRIES")
customTests = os.Getenv("TESTS")
debug = os.Getenv("DEBUG") == "true"
githubAction = os.Getenv("GH_ACTION") == "true"
customTests = os.Getenv("TESTS")

success = aurora.Green("[✓]").String()
failed = aurora.Red("[✘]").String()
Expand Down Expand Up @@ -63,13 +61,16 @@ func main() {
os.Exit(1)
}

failedTestCases := runTests(toMap(toSlice(customTests)))
failedTestTemplatePaths := runTests(toMap(toSlice(customTests)))

if githubAction {
if retryOnFailure(failedTestCases) {
os.Exit(1)
if len(failedTestTemplatePaths) > 0 {
if githubAction {
debug = true
fmt.Println("::group::Failed integration tests in debug mode")
_ = runTests(failedTestTemplatePaths)
fmt.Println("::endgroup::")
}
} else if len(failedTestCases) > 0 {

os.Exit(1)
}
}
Expand All @@ -85,8 +86,8 @@ func debugTests() {
}
}

func runTests(customTemplatePaths map[string]struct{}) map[string]testutils.TestCase {
failedTestCase := map[string]testutils.TestCase{}
func runTests(customTemplatePaths map[string]struct{}) map[string]struct{} {
failedTestTemplatePaths := map[string]struct{}{}

for proto, testCases := range protocolTests {
if len(customTemplatePaths) == 0 {
Expand All @@ -95,14 +96,14 @@ func runTests(customTemplatePaths map[string]struct{}) map[string]testutils.Test

for templatePath, testCase := range testCases {
if len(customTemplatePaths) == 0 || contains(customTemplatePaths, templatePath) {
if _, err := execute(testCase, templatePath); err != nil {
failedTestCase[templatePath] = testCase
if failedTemplatePath, err := execute(testCase, templatePath); err != nil {
failedTestTemplatePaths[failedTemplatePath] = struct{}{}
}
}
}
}

return failedTestCase
return failedTestTemplatePaths
}

func execute(testCase testutils.TestCase, templatePath string) (string, error) {
Expand Down Expand Up @@ -144,29 +145,3 @@ func contains(input map[string]struct{}, value string) bool {
_, ok := input[value]
return ok
}

// retries failed test cases and run the last retry in debug mode
// if any case failed in retry retrun true
func retryOnFailure(failedTestCases map[string]testutils.TestCase) bool {
retries, _ := strconv.Atoi(githubActionRetries)
var failed bool
for templatePath, testCase := range failedTestCases {
var err error
debug = false
fmt.Println("::group::Failed integration test", templatePath)
for i := 0; i < retries; i++ {
if (retries - i) == 1 {
debug = true
}
_, err = execute(testCase, templatePath)
if err == nil {
break
}
}
fmt.Println("::endgroup::")
if err != nil {
failed = true
}
}
return failed
}

0 comments on commit d32c9c7

Please sign in to comment.