Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concept hooks return status response #2492

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions execution/scenarioExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,50 @@ func (e *scenarioExecutor) notifyAfterScenarioHook(scenarioResult *result.Scenar
e.pluginHandler.NotifyPlugins(message)
}

func (e *scenarioExecutor) notifyBeforeConcept(conceptResult *result.ScenarioResult) {
func (e *scenarioExecutor) notifyBeforeConceptHook(conceptResult *result.ScenarioResult) *gauge_messages.ProtoExecutionResult {
message := &gauge_messages.Message{MessageType: gauge_messages.Message_ConceptExecutionStarting,
ConceptExecutionStartingRequest: &gauge_messages.ConceptExecutionStartingRequest{CurrentExecutionInfo: e.currentExecutionInfo, Stream: int32(e.stream)}}
e.pluginHandler.NotifyPlugins(message)
var res *gauge_messages.ProtoExecutionResult = nil
if (e.runner.Info().ConceptMessages) {
_ = e.runner.ExecuteAndGetStatus(message)
res = e.runner.ExecuteAndGetStatus(message)
conceptResult.ProtoScenario.PostHookMessages = res.Message
conceptResult.ProtoScenario.PostHookScreenshotFiles = res.ScreenshotFiles
if res.GetFailed() {
setScenarioFailure(e.currentExecutionInfo)
handleHookFailure(conceptResult, res, result.AddPreHook)
}
}
e.notifyBeforeConcept(conceptResult)
return res
}

func (e *scenarioExecutor) notifyAfterConcept(conceptResult *result.ScenarioResult) {
func (e *scenarioExecutor) notifyAfterConceptHook(conceptResult *result.ScenarioResult) *gauge_messages.ProtoExecutionResult {
message := &gauge_messages.Message{MessageType: gauge_messages.Message_ConceptExecutionEnding,
ConceptExecutionEndingRequest: &gauge_messages.ConceptExecutionEndingRequest{CurrentExecutionInfo: e.currentExecutionInfo, Stream: int32(e.stream)}}
e.pluginHandler.NotifyPlugins(message)
var res *gauge_messages.ProtoExecutionResult = nil
if (e.runner.Info().ConceptMessages) {
_ = e.runner.ExecuteAndGetStatus(message)
res = e.runner.ExecuteAndGetStatus(message)
conceptResult.ProtoScenario.PostHookMessages = res.Message
conceptResult.ProtoScenario.PostHookScreenshotFiles = res.ScreenshotFiles
if res.GetFailed() {
setScenarioFailure(e.currentExecutionInfo)
handleHookFailure(conceptResult, res, result.AddPostHook)
}
}
e.notifyAfterConcept(conceptResult)
return res
}

func (e *scenarioExecutor) notifyBeforeConcept(conceptResult *result.ScenarioResult) {
message := &gauge_messages.Message{MessageType: gauge_messages.Message_ConceptExecutionStarting,
ConceptExecutionStartingRequest: &gauge_messages.ConceptExecutionStartingRequest{CurrentExecutionInfo: e.currentExecutionInfo, Stream: int32(e.stream)}}
e.pluginHandler.NotifyPlugins(message)
}

func (e *scenarioExecutor) notifyAfterConcept(conceptResult *result.ScenarioResult) {
message := &gauge_messages.Message{MessageType: gauge_messages.Message_ConceptExecutionEnding,
ConceptExecutionEndingRequest: &gauge_messages.ConceptExecutionEndingRequest{CurrentExecutionInfo: e.currentExecutionInfo, Stream: int32(e.stream)}}
e.pluginHandler.NotifyPlugins(message)
}

func (e *scenarioExecutor) createStepRequest(protoStep *gauge_messages.ProtoStep) *gauge_messages.ExecuteStepRequest {
Expand Down Expand Up @@ -207,7 +235,13 @@ func (e *scenarioExecutor) executeConcept(item *gauge.Step, protoConcept *gauge_
stepRequest := e.createStepRequest(protoConcept.ConceptStep)
e.currentExecutionInfo.CurrentStep = &gauge_messages.StepInfo{Step: stepRequest, IsFailed: false}
event.Notify(event.NewExecutionEvent(event.ConceptStart, item, nil, e.stream, e.currentExecutionInfo))
e.notifyBeforeConcept(scenarioResult)
if e.notifyBeforeConceptHook(scenarioResult).GetFailed() {
scenarioResult.SetFailure()
cptResult.UpdateConceptExecResult()
event.Notify(event.NewExecutionEvent(event.ConceptEnd, nil, cptResult, e.stream, e.currentExecutionInfo))
e.notifyAfterConcept(scenarioResult)
return cptResult
}

var conceptStepIndex int
for _, protoStep := range protoConcept.Steps {
Expand All @@ -223,8 +257,8 @@ func (e *scenarioExecutor) executeConcept(item *gauge.Step, protoConcept *gauge_
// The concept is finishing after a step failure
// Restore the Concept step data in the Execution info that is sent to plugins
e.currentExecutionInfo.CurrentStep = &gauge_messages.StepInfo{Step: stepRequest, IsFailed: false}
defer event.Notify(event.NewExecutionEvent(event.ConceptEnd, nil, cptResult, e.stream, e.currentExecutionInfo))
defer e.notifyAfterConcept(scenarioResult)
event.Notify(event.NewExecutionEvent(event.ConceptEnd, nil, cptResult, e.stream, e.currentExecutionInfo))
e.notifyAfterConcept(scenarioResult)

return cptResult
}
Expand All @@ -234,8 +268,11 @@ func (e *scenarioExecutor) executeConcept(item *gauge.Step, protoConcept *gauge_

// Restore the Concept step to the Execution info that is sent to plugins
e.currentExecutionInfo.CurrentStep = &gauge_messages.StepInfo{Step: stepRequest, IsFailed: false}
defer event.Notify(event.NewExecutionEvent(event.ConceptEnd, nil, cptResult, e.stream, e.currentExecutionInfo))
defer e.notifyAfterConcept(scenarioResult)
event.Notify(event.NewExecutionEvent(event.ConceptEnd, nil, cptResult, e.stream, e.currentExecutionInfo))
if e.notifyAfterConceptHook(scenarioResult).GetFailed() {
scenarioResult.SetFailure()
cptResult.UpdateConceptExecResult()
}

return cptResult
}
Expand Down
4 changes: 2 additions & 2 deletions 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-20231211152919-94c93e29f0b9
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240215051240-9e50dbd68dfa
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240224015747-16d1a26a9fea
github.com/golang/protobuf v1.5.3
github.com/magiconair/properties v1.8.7
github.com/natefinch/lumberjack v2.0.0+incompatible
Expand All @@ -18,7 +18,7 @@ require (
github.com/sourcegraph/jsonrpc2 v0.2.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.32.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,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-20231211152919-94c93e29f0b9 h1:OwggKdL8AeteB2y0xJzloieq9CMhYG7YmKKMh6D8FLs=
github.com/getgauge/common v0.0.0-20231211152919-94c93e29f0b9/go.mod h1:p/Q0+qO2bLq08PuxaHrxIgkvKlGGYHyXad33+zKIiXU=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240215051240-9e50dbd68dfa h1:yUuCvJmCxXlC4nhEtGjVDjgYTuB6t7lqN9aX/9FlQkc=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240215051240-9e50dbd68dfa/go.mod h1:qf8Dv2iFBwlgpBZBOKjW9JDaYi5lHqXNYXEHTXd62Uw=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240224015747-16d1a26a9fea h1:l2xnnhqp0wlvCwOQn+TGk3yBfqOdUw2hYRf5UwAl1C4=
github.com/getgauge/gauge-proto/go/gauge_messages v0.0.0-20240224015747-16d1a26a9fea/go.mod h1:qf8Dv2iFBwlgpBZBOKjW9JDaYi5lHqXNYXEHTXd62Uw=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
Expand Down Expand Up @@ -69,8 +69,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
Expand Down
8 changes: 4 additions & 4 deletions runner/grpcRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ func (r *GrpcRunner) invokeServiceFor(message *gm.Message) (*gm.Message, error)
_, _ = r.RunnerClient.Kill(context.Background(), message.KillProcessRequest)
return nil, nil
case gm.Message_ConceptExecutionStarting:
_, err := r.RunnerClient.NotifyConceptExecutionStarting(context.Background(), message.ConceptExecutionStartingRequest)
return nil, err
response, err := r.RunnerClient.NotifyConceptExecutionStarting(context.Background(), message.ConceptExecutionStartingRequest)
return &gm.Message{MessageType: gm.Message_ExecutionStatusResponse, ExecutionStatusResponse: response}, err
case gm.Message_ConceptExecutionEnding:
_, err := r.RunnerClient.NotifyConceptExecutionEnding(context.Background(), message.ConceptExecutionEndingRequest)
return nil, err
response, err := r.RunnerClient.NotifyConceptExecutionEnding(context.Background(), message.ConceptExecutionEndingRequest)
return &gm.Message{MessageType: gm.Message_ExecutionStatusResponse, ExecutionStatusResponse: response}, err
default:
return nil, nil
}
Expand Down
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, 2}
var CurrentGaugeVersion = &Version{1, 6, 3}

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