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

Fix step duration calculation #616

Merged
merged 1 commit into from
Apr 8, 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
16 changes: 14 additions & 2 deletions internal/models/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ type PickleStepResult struct {
}

// NewStepResult ...
func NewStepResult(pickleID, pickleStepID string, match *StepDefinition) PickleStepResult {
return PickleStepResult{FinishedAt: utils.TimeNowFunc(), PickleID: pickleID, PickleStepID: pickleStepID, Def: match}
func NewStepResult(
status StepResultStatus,
pickleID, pickleStepID string,
match *StepDefinition,
err error,
) PickleStepResult {
return PickleStepResult{
Status: status,
FinishedAt: utils.TimeNowFunc(),
Err: err,
PickleID: pickleID,
PickleStepID: pickleStepID,
Def: match,
}
}

// StepResultStatus ...
Expand Down
44 changes: 15 additions & 29 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ func (s *suite) matchStep(step *messages.PickleStep) *models.StepDefinition {
}

func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scenarioErr error, isFirst, isLast bool) (rctx context.Context, err error) {
var (
match *models.StepDefinition
sr = models.NewStepResult(pickle.Id, step.Id, match)
)
var match *models.StepDefinition

rctx = ctx
sr.Status = StepUndefined
status := StepUndefined

// user multistep definitions may panic
defer func() {
Expand All @@ -105,19 +102,19 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena

switch {
case errors.Is(err, ErrPending):
sr.Status = StepPending
status = StepPending
case errors.Is(err, ErrSkip), err == nil && scenarioErr != nil:
sr.Status = StepSkipped
status = StepSkipped
case errors.Is(err, ErrUndefined):
sr.Status = StepUndefined
status = StepUndefined
case err != nil:
sr.Status = StepFailed
status = StepFailed
case err == nil && scenarioErr == nil:
sr.Status = StepPassed
status = StepPassed
}

// Run after step handlers.
rctx, err = s.runAfterStepHooks(ctx, step, sr.Status, err)
rctx, err = s.runAfterStepHooks(ctx, step, status, err)

shouldFail := s.shouldFail(err)

Expand All @@ -132,25 +129,20 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena

switch {
case err == nil:
sr.Status = models.Passed
sr := models.NewStepResult(models.Passed, pickle.Id, step.Id, match, nil)
s.storage.MustInsertPickleStepResult(sr)

s.fmt.Passed(pickle, step, match.GetInternalStepDefinition())
case errors.Is(err, ErrPending):
sr.Status = models.Pending
sr := models.NewStepResult(models.Pending, pickle.Id, step.Id, match, nil)
s.storage.MustInsertPickleStepResult(sr)

s.fmt.Pending(pickle, step, match.GetInternalStepDefinition())
case errors.Is(err, ErrSkip):
sr.Status = models.Skipped
sr := models.NewStepResult(models.Skipped, pickle.Id, step.Id, match, nil)
s.storage.MustInsertPickleStepResult(sr)

s.fmt.Skipped(pickle, step, match.GetInternalStepDefinition())
default:
sr.Status = models.Failed
sr.Err = err
sr := models.NewStepResult(models.Failed, pickle.Id, step.Id, match, err)
s.storage.MustInsertPickleStepResult(sr)

s.fmt.Failed(pickle, step, match.GetInternalStepDefinition(), err)
}
}()
Expand All @@ -165,14 +157,11 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena

match = s.matchStep(step)
s.storage.MustInsertStepDefintionMatch(step.AstNodeIds[0], match)
sr.Def = match
s.fmt.Defined(pickle, step, match.GetInternalStepDefinition())

if err != nil {
sr = models.NewStepResult(pickle.Id, step.Id, match)
sr.Status = models.Failed
sr := models.NewStepResult(models.Failed, pickle.Id, step.Id, match, nil)
s.storage.MustInsertPickleStepResult(sr)

return ctx, err
}

Expand All @@ -191,20 +180,17 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena
Nested: match.Nested,
Undefined: undef,
}
sr.Def = match
}

sr = models.NewStepResult(pickle.Id, step.Id, match)
sr.Status = models.Undefined
sr := models.NewStepResult(models.Undefined, pickle.Id, step.Id, match, nil)
s.storage.MustInsertPickleStepResult(sr)

s.fmt.Undefined(pickle, step, match.GetInternalStepDefinition())
return ctx, ErrUndefined
}

if scenarioErr != nil {
sr = models.NewStepResult(pickle.Id, step.Id, match)
sr.Status = models.Skipped
sr := models.NewStepResult(models.Skipped, pickle.Id, step.Id, match, nil)
s.storage.MustInsertPickleStepResult(sr)

s.fmt.Skipped(pickle, step, match.GetInternalStepDefinition())
Expand Down
Loading