Skip to content

Commit da57dd0

Browse files
Fix step duration calculation (#616)
1 parent 153db4e commit da57dd0

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

internal/models/results.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ type PickleStepResult struct {
3131
}
3232

3333
// NewStepResult ...
34-
func NewStepResult(pickleID, pickleStepID string, match *StepDefinition) PickleStepResult {
35-
return PickleStepResult{FinishedAt: utils.TimeNowFunc(), PickleID: pickleID, PickleStepID: pickleStepID, Def: match}
34+
func NewStepResult(
35+
status StepResultStatus,
36+
pickleID, pickleStepID string,
37+
match *StepDefinition,
38+
err error,
39+
) PickleStepResult {
40+
return PickleStepResult{
41+
Status: status,
42+
FinishedAt: utils.TimeNowFunc(),
43+
Err: err,
44+
PickleID: pickleID,
45+
PickleStepID: pickleStepID,
46+
Def: match,
47+
}
3648
}
3749

3850
// StepResultStatus ...

suite.go

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,10 @@ func (s *suite) matchStep(step *messages.PickleStep) *models.StepDefinition {
7777
}
7878

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

8582
rctx = ctx
86-
sr.Status = StepUndefined
83+
status := StepUndefined
8784

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

106103
switch {
107104
case errors.Is(err, ErrPending):
108-
sr.Status = StepPending
105+
status = StepPending
109106
case errors.Is(err, ErrSkip), err == nil && scenarioErr != nil:
110-
sr.Status = StepSkipped
107+
status = StepSkipped
111108
case errors.Is(err, ErrUndefined):
112-
sr.Status = StepUndefined
109+
status = StepUndefined
113110
case err != nil:
114-
sr.Status = StepFailed
111+
status = StepFailed
115112
case err == nil && scenarioErr == nil:
116-
sr.Status = StepPassed
113+
status = StepPassed
117114
}
118115

119116
// Run after step handlers.
120-
rctx, err = s.runAfterStepHooks(ctx, step, sr.Status, err)
117+
rctx, err = s.runAfterStepHooks(ctx, step, status, err)
121118

122119
shouldFail := s.shouldFail(err)
123120

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

133130
switch {
134131
case err == nil:
135-
sr.Status = models.Passed
132+
sr := models.NewStepResult(models.Passed, pickle.Id, step.Id, match, nil)
136133
s.storage.MustInsertPickleStepResult(sr)
137-
138134
s.fmt.Passed(pickle, step, match.GetInternalStepDefinition())
139135
case errors.Is(err, ErrPending):
140-
sr.Status = models.Pending
136+
sr := models.NewStepResult(models.Pending, pickle.Id, step.Id, match, nil)
141137
s.storage.MustInsertPickleStepResult(sr)
142-
143138
s.fmt.Pending(pickle, step, match.GetInternalStepDefinition())
144139
case errors.Is(err, ErrSkip):
145-
sr.Status = models.Skipped
140+
sr := models.NewStepResult(models.Skipped, pickle.Id, step.Id, match, nil)
146141
s.storage.MustInsertPickleStepResult(sr)
147-
148142
s.fmt.Skipped(pickle, step, match.GetInternalStepDefinition())
149143
default:
150-
sr.Status = models.Failed
151-
sr.Err = err
144+
sr := models.NewStepResult(models.Failed, pickle.Id, step.Id, match, err)
152145
s.storage.MustInsertPickleStepResult(sr)
153-
154146
s.fmt.Failed(pickle, step, match.GetInternalStepDefinition(), err)
155147
}
156148
}()
@@ -165,14 +157,11 @@ func (s *suite) runStep(ctx context.Context, pickle *Scenario, step *Step, scena
165157

166158
match = s.matchStep(step)
167159
s.storage.MustInsertStepDefintionMatch(step.AstNodeIds[0], match)
168-
sr.Def = match
169160
s.fmt.Defined(pickle, step, match.GetInternalStepDefinition())
170161

171162
if err != nil {
172-
sr = models.NewStepResult(pickle.Id, step.Id, match)
173-
sr.Status = models.Failed
163+
sr := models.NewStepResult(models.Failed, pickle.Id, step.Id, match, nil)
174164
s.storage.MustInsertPickleStepResult(sr)
175-
176165
return ctx, err
177166
}
178167

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

197-
sr = models.NewStepResult(pickle.Id, step.Id, match)
198-
sr.Status = models.Undefined
185+
sr := models.NewStepResult(models.Undefined, pickle.Id, step.Id, match, nil)
199186
s.storage.MustInsertPickleStepResult(sr)
200187

201188
s.fmt.Undefined(pickle, step, match.GetInternalStepDefinition())
202189
return ctx, ErrUndefined
203190
}
204191

205192
if scenarioErr != nil {
206-
sr = models.NewStepResult(pickle.Id, step.Id, match)
207-
sr.Status = models.Skipped
193+
sr := models.NewStepResult(models.Skipped, pickle.Id, step.Id, match, nil)
208194
s.storage.MustInsertPickleStepResult(sr)
209195

210196
s.fmt.Skipped(pickle, step, match.GetInternalStepDefinition())

0 commit comments

Comments
 (0)