This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch verify/fast in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
commit 1b7d2708bf8c1f21f72807312dfeec75dcc6013d Author: kezhenxu94 <[email protected]> AuthorDate: Wed Aug 11 19:27:56 2021 +0800 Some enhancements - Cleanup if `cleanup.on == Always` and error happens in `setup` step. - Fail `setup` step if there is command fail in the `steps.command`. - Retry per case instead of all cases in `verify` step. - Delete unused function `Which`. --- commands/run/run.go | 51 ++++++++++++++++++++++------------------------- commands/verify/verify.go | 28 +++++++++++--------------- internal/util/utils.go | 9 +-------- 3 files changed, 37 insertions(+), 51 deletions(-) diff --git a/commands/run/run.go b/commands/run/run.go index b35da3e..fd5eb4a 100644 --- a/commands/run/run.go +++ b/commands/run/run.go @@ -47,6 +47,12 @@ func runAccordingE2E() error { return config.GlobalConfig.Error } + // If cleanup.on == Always and there is error in setup step, we should defer cleanup step right now. + cleanupOnCondition := config.GlobalConfig.E2EConfig.Cleanup.On + if cleanupOnCondition == constant.CleanUpAlways { + defer cleanup0() + } + // setup part err := setup.DoSetupAccordingE2E() if err != nil { @@ -54,36 +60,19 @@ func runAccordingE2E() error { } logger.Log.Infof("setup part finished successfully") - // cleanup part - defer func() { - clean := true + if cleanupOnCondition != constant.CleanUpAlways { + defer func() { + shouldCleanup := (cleanupOnCondition == constant.CleanUpOnSuccess && err == nil) || + (cleanupOnCondition == constant.CleanUpOnFailure && err != nil) - switch config.GlobalConfig.E2EConfig.Cleanup.On { - case constant.CleanUpNever: - clean = false - case constant.CleanUpOnSuccess: - // failed - if err != nil { - clean = false + if !shouldCleanup { + logger.Log.Infof("don't cleanup according to config") + return } - case constant.CleanUpOnFailure: - // success - if err == nil { - clean = false - } - } - if !clean { - logger.Log.Infof("cleanup passed according to config") - return - } - - err = cleanup.DoCleanupAccordingE2E() - if err != nil { - logger.Log.Errorf("cleanup part error: %s", err) - } - logger.Log.Infof("cleanup part finished successfully") - }() + cleanup0() + }() + } // trigger part err = trigger.DoActionAccordingE2E() @@ -101,3 +90,11 @@ func runAccordingE2E() error { return nil } + +func cleanup0() { + if err := cleanup.DoCleanupAccordingE2E(); err != nil { + logger.Log.Errorf("cleanup part error: %s", err) + } else { + logger.Log.Infof("cleanup part finished successfully") + } +} diff --git a/commands/verify/verify.go b/commands/verify/verify.go index 3f5146a..e979b41 100644 --- a/commands/verify/verify.go +++ b/commands/verify/verify.go @@ -101,25 +101,21 @@ func DoVerifyAccordingConfig() error { retryInterval = 1000 } - var err error - for current := 1; current <= retryCount; current++ { - for _, v := range e2eConfig.Verify.Cases { - if v.GetExpected() != "" { - if err = verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); err != nil { - break - } + for idx, v := range e2eConfig.Verify.Cases { + if v.GetExpected() == "" { + return fmt.Errorf("the expected data file for case[%v] is not specified", idx) + } + for current := 1; current <= retryCount; current++ { + if err := verifySingleCase(v.GetExpected(), v.GetActual(), v.Query); err == nil { + break + } else if current != retryCount { + logger.Log.Warnf("verify case failure, will continue retry, %v", err) + time.Sleep(time.Duration(retryInterval) * time.Millisecond) } else { - return fmt.Errorf("the expected data file is not specified") + return err } } - - if err != nil && current != retryCount { - logger.Log.Warnf("verify case failure, will continue retry, %v", err) - time.Sleep(time.Duration(retryInterval) * time.Millisecond) - } else if err == nil { - return nil - } } - return err + return nil } diff --git a/internal/util/utils.go b/internal/util/utils.go index 495586c..1e84ea1 100644 --- a/internal/util/utils.go +++ b/internal/util/utils.go @@ -26,13 +26,6 @@ import ( "os/exec" ) -// Which checks if binary is present in PATH. -func Which(binary string) error { - _, err := exec.LookPath(binary) - - return err -} - // PathExist checks if a file/directory is exist. func PathExist(_path string) bool { _, err := os.Stat(_path) @@ -56,7 +49,7 @@ func ReadFileContent(filename string) (string, error) { // ExecuteCommand executes the given command and returns the result. func ExecuteCommand(cmd string) (string, error) { - command := exec.Command("bash", "-c", cmd) + command := exec.Command("bash", "-ec", cmd) outinfo := bytes.Buffer{} command.Stdout = &outinfo
