Skip to content

Commit

Permalink
Handle skip scenario during execution
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>
  • Loading branch information
PiotrNestor committed Mar 21, 2024
1 parent 0db4a49 commit bb445df
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
8 changes: 8 additions & 0 deletions execution/result/scenarioResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func (s ScenarioResult) GetFailed() bool {
return s.ProtoScenario.GetExecutionStatus() == gauge_messages.ExecutionStatus_FAILED
}

func (s ScenarioResult) SetSkippedScenario() {
s.ProtoScenario.ExecutionStatus = gauge_messages.ExecutionStatus_SKIPPED
}

func (s ScenarioResult) GetSkippedScenario() bool {
return s.ProtoScenario.GetExecutionStatus() == gauge_messages.ExecutionStatus_SKIPPED
}

func (s ScenarioResult) AddItems(protoItems []*gauge_messages.ProtoItem) {
s.ProtoScenario.ScenarioItems = append(s.ProtoScenario.ScenarioItems, protoItems...)
}
Expand Down
9 changes: 9 additions & 0 deletions execution/result/stepResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ func (s *StepResult) GetStepFailed() bool {
return s.StepFailed
}

func (s *StepResult) GetSkippedScenario() bool {
for _, ok := range s.ProtoStep.StepExecutionResult.ExecutionResult.GetSkipScenario() {
if ok {
return true
}
}
return false
}

// GetStackTrace returns the stacktrace for step failure
func (s *StepResult) GetStackTrace() string {
return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetStackTrace()
Expand Down
35 changes: 33 additions & 2 deletions execution/scenarioExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,24 @@ func (e *scenarioExecutor) execute(i gauge.Item, r result.Result) {
}
e.notifyBeforeScenarioHook(scenarioResult)

if !scenarioResult.GetFailed() {
if !(scenarioResult.GetFailed() || scenarioResult.GetSkippedScenario()) {
protoContexts := scenarioResult.ProtoScenario.GetContexts()
protoScenItems := scenarioResult.ProtoScenario.GetScenarioItems()
// context and steps are not appended together since sometime it cause the issue and the steps in step list and proto step list differs.
// This is done to fix https://github.com/getgauge/gauge/issues/1629
if e.executeSteps(e.contexts, protoContexts, scenarioResult) {
e.executeSteps(scenario.Steps, protoScenItems, scenarioResult)
if !scenarioResult.GetSkippedScenario() {
e.executeSteps(scenario.Steps, protoScenItems, scenarioResult)
}
}
// teardowns are not appended to previous call to executeSteps to ensure they are run irrespective of context/step failure
e.executeSteps(e.teardowns, scenarioResult.ProtoScenario.GetTearDownSteps(), scenarioResult)
}

if scenarioResult.GetSkippedScenario() {
setSkipInfoInResult(scenarioResult, scenario, e.errMap)
}

e.notifyAfterScenarioHook(scenarioResult)
scenarioResult.UpdateExecutionTime()
}
Expand Down Expand Up @@ -123,6 +129,9 @@ func (e *scenarioExecutor) notifyBeforeScenarioHook(scenarioResult *result.Scena
setScenarioFailure(e.currentExecutionInfo)
handleHookFailure(scenarioResult, res, result.AddPreHook)
}
if skippedScenario(res.GetSkipScenario()) {
scenarioResult.SetSkippedScenario()
}
message.ScenarioExecutionStartingRequest.ScenarioResult = gauge.ConvertToProtoScenarioResult(scenarioResult)
e.pluginHandler.NotifyPlugins(message)
}
Expand Down Expand Up @@ -205,6 +214,11 @@ func (e *scenarioExecutor) executeSteps(steps []*gauge.Step, protoItems []*gauge
return false
}
}
if scenarioResult.GetSkippedScenario() {
// The step execution resulted in SkipScenario.
// The rest of steps execution is skipped
break;
}
}
}
return true
Expand All @@ -222,6 +236,9 @@ func (e *scenarioExecutor) executeStep(step *gauge.Step, protoItem *gauge_messag
se := &stepExecutor{runner: e.runner, pluginHandler: e.pluginHandler, currentExecutionInfo: e.currentExecutionInfo, stream: e.stream}
res := se.executeStep(step, protoItem.GetStep())
protoItem.GetStep().StepExecutionResult = res.ProtoStepExecResult()
if skippedScenario(res.ProtoStepExecResult().ExecutionResult.SkipScenario) {
scenarioResult.SetSkippedScenario()
}
failed = res.GetFailed()
recoverable = res.ProtoStepExecResult().GetExecutionResult().GetRecoverableError()
}
Expand Down Expand Up @@ -262,6 +279,11 @@ func (e *scenarioExecutor) executeConcept(item *gauge.Step, protoConcept *gauge_

return cptResult
}
if scenarioResult.GetSkippedScenario() {
// The step execution resulted in SkipScenario.
// The rest of steps execution is skipped
break;
}
}
}
cptResult.UpdateConceptExecResult()
Expand All @@ -277,6 +299,15 @@ func (e *scenarioExecutor) executeConcept(item *gauge.Step, protoConcept *gauge_
return cptResult
}

func skippedScenario(result []bool) bool {
for _, ok := range result {
if ok {
return true
}
}
return false
}

func setStepFailure(executionInfo *gauge_messages.ExecutionInfo) {
setScenarioFailure(executionInfo)
executionInfo.CurrentStep.IsFailed = true
Expand Down
5 changes: 5 additions & 0 deletions execution/stepExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (e *stepExecutor) executeStep(step *gauge.Step, protoStep *gauge_messages.P
e.currentExecutionInfo.CurrentStep.StackTrace = stepExecutionStatus.GetStackTrace()
setStepFailure(e.currentExecutionInfo)
stepResult.SetStepFailure()
} else if stepResult.GetSkippedScenario() {
e.currentExecutionInfo.CurrentStep.ErrorMessage = stepExecutionStatus.GetErrorMessage()
e.currentExecutionInfo.CurrentStep.StackTrace = stepExecutionStatus.GetStackTrace()
}
stepResult.SetProtoExecResult(stepExecutionStatus)
}
Expand Down Expand Up @@ -95,3 +98,5 @@ func (e *stepExecutor) notifyAfterStepHook(stepResult *result.StepResult) {
m.StepExecutionEndingRequest.StepResult = gauge.ConvertToProtoStepResult(stepResult)
e.pluginHandler.NotifyPlugins(m)
}


2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// CurrentGaugeVersion represents the current version of Gauge
var CurrentGaugeVersion = &Version{1, 6, 4}
var CurrentGaugeVersion = &Version{1, 6, 5}

// BuildMetadata represents build information of current release (e.g, nightly build information)
var BuildMetadata = ""
Expand Down

0 comments on commit bb445df

Please sign in to comment.