Skip to content

Commit

Permalink
Programmatic skip scenario feature (#2502)
Browse files Browse the repository at this point in the history
* Use local gauge-proto

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Handle skip scenario during execution

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Handle message when skip scenario

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Handle skip scenario message

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Golang version update

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Update using gauge-proto from git

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

---------

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>
  • Loading branch information
PiotrNestor committed May 22, 2024
1 parent 522443e commit f974c53
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 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
4 changes: 4 additions & 0 deletions execution/result/stepResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (s *StepResult) GetStepFailed() bool {
return s.StepFailed
}

func (s *StepResult) GetSkippedScenario() bool {
return s.ProtoStep.StepExecutionResult.ExecutionResult.GetSkipScenario()
}

// GetStackTrace returns the stacktrace for step failure
func (s *StepResult) GetStackTrace() string {
return s.ProtoStep.GetStepExecutionResult().GetExecutionResult().GetStackTrace()
Expand Down
40 changes: 38 additions & 2 deletions execution/scenarioExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,25 @@ 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() {
e.skippedScenarioUpdateErrMap(i, r)
setSkipInfoInResult(scenarioResult, scenario, e.errMap)
}

e.notifyAfterScenarioHook(scenarioResult)
scenarioResult.UpdateExecutionTime()
}
Expand Down Expand Up @@ -123,6 +130,10 @@ func (e *scenarioExecutor) notifyBeforeScenarioHook(scenarioResult *result.Scena
setScenarioFailure(e.currentExecutionInfo)
handleHookFailure(scenarioResult, res, result.AddPreHook)
}
if res.GetSkipScenario() {
scenarioResult.SetSkippedScenario()
scenarioResult.ProtoScenario.PreHookMessages = []string{res.ErrorMessage}
}
message.ScenarioExecutionStartingRequest.ScenarioResult = gauge.ConvertToProtoScenarioResult(scenarioResult)
e.pluginHandler.NotifyPlugins(message)
}
Expand Down Expand Up @@ -205,6 +216,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 +238,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 res.ProtoStepExecResult().ExecutionResult.GetSkipScenario() {
scenarioResult.SetSkippedScenario()
}
failed = res.GetFailed()
recoverable = res.ProtoStepExecResult().GetExecutionResult().GetRecoverableError()
}
Expand Down Expand Up @@ -262,6 +281,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 Down Expand Up @@ -296,3 +320,15 @@ func setScenarioFailure(executionInfo *gauge_messages.ExecutionInfo) {
setSpecFailure(executionInfo)
executionInfo.CurrentScenario.IsFailed = true
}

func (e *scenarioExecutor) skippedScenarioUpdateErrMap(i gauge.Item, r result.Result) {
scenario := i.(*gauge.Scenario)
scenarioResult := r.(*result.ScenarioResult)
if len(scenarioResult.ProtoScenario.PreHookMessages) > 0 {
e.errMap.ScenarioErrs[scenario] = append([]error{errors.New(scenarioResult.ProtoScenario.PreHookMessages[0])}, e.errMap.ScenarioErrs[scenario]...)
scenarioResult.ProtoScenario.SkipErrors = scenarioResult.ProtoScenario.PreHookMessages
} else {
e.errMap.ScenarioErrs[scenario] = append([]error{errors.New(e.currentExecutionInfo.CurrentStep.ErrorMessage)}, e.errMap.ScenarioErrs[scenario]...)
scenarioResult.ProtoScenario.SkipErrors = []string{e.currentExecutionInfo.CurrentStep.ErrorMessage}
}
}
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/daviddengcn/go-colortext v1.0.0
github.com/fsnotify/fsnotify v1.7.0
github.com/getgauge/common v0.0.0-20240331100109-225c78ec8f30
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240331094732-ac276d4db3b9
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240402072853-303b17b7c486
github.com/golang/protobuf v1.5.4
github.com/magiconair/properties v1.8.7
github.com/natefinch/lumberjack v2.0.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/getgauge/common v0.0.0-20240331100109-225c78ec8f30 h1:pGrxY3IZb/1wwlSUSKYplmQ9kEh4rRpcAvQYI2WcxX0=
github.com/getgauge/common v0.0.0-20240331100109-225c78ec8f30/go.mod h1:q7UW1tDojJwCQPUHaE1ny71IZIDuKlsgh3Tyr5wAZDk=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240331094732-ac276d4db3b9 h1:g3Qhoj4ho3txgMcOJ3ivvEhfahaR6t8XTkf5K5M1VSA=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240331094732-ac276d4db3b9/go.mod h1:ZOT57PjvIqY31eGcwhj/LSi/K6ULBE1AhFcIMzWkmPg=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240402072853-303b17b7c486 h1:kb/Ey0fFX+EHPmFcOEZDa0s4bgsRpRF8iDJEcbZPgLU=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240402072853-303b17b7c486/go.mod h1:ZOT57PjvIqY31eGcwhj/LSi/K6ULBE1AhFcIMzWkmPg=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
Expand Down

0 comments on commit f974c53

Please sign in to comment.