mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
fix: improve step execution handling with interrupt support and result logging
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506241946
|
v5.0.0-beta-2506242108
|
||||||
|
|||||||
@@ -865,23 +865,9 @@ func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error)
|
|||||||
|
|
||||||
var stepResults []*StepResult
|
var stepResults []*StepResult
|
||||||
|
|
||||||
// execute with loops as outer iteration
|
// defer to save results regardless of how the function exits
|
||||||
for _, task := range tasks {
|
defer func() {
|
||||||
// execute step with merged variables
|
// Save all completed results to summary
|
||||||
stepResult, err := r.executeStepWithVariables(step, task.stepName, task.parameters)
|
|
||||||
if err != nil {
|
|
||||||
if r.caseRunner.hrpRunner.failfast {
|
|
||||||
return nil, errors.Wrap(err, "execute step failed")
|
|
||||||
}
|
|
||||||
log.Error().Err(err).Str("step", task.stepName).Msg("execute step failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
stepResults = append(stepResults, stepResult)
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the last step result, or nil if no steps were executed
|
|
||||||
if len(stepResults) > 0 {
|
|
||||||
// add all step results to summary
|
|
||||||
for _, result := range stepResults {
|
for _, result := range stepResults {
|
||||||
r.summary.AddStepResult(result)
|
r.summary.AddStepResult(result)
|
||||||
// update extracted variables from the last result
|
// update extracted variables from the last result
|
||||||
@@ -891,22 +877,54 @@ func (r *SessionRunner) RunStep(step IStep) (stepResult *StepResult, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log final result
|
// log final result
|
||||||
lastResult := stepResults[len(stepResults)-1]
|
if err == nil && stepResult.Success {
|
||||||
if lastResult.Success {
|
|
||||||
log.Info().Str("step", stepName).
|
log.Info().Str("step", stepName).
|
||||||
Str("type", stepType).
|
Str("type", stepType).
|
||||||
Bool("success", true).
|
Bool("success", true).
|
||||||
Int64("elapsed(ms)", lastResult.Elapsed).
|
Int64("elapsed(ms)", stepResult.Elapsed).
|
||||||
Interface("exportVars", lastResult.ExportVars).
|
Interface("exportVars", stepResult.ExportVars).
|
||||||
Msg(RUN_STEP_END)
|
Msg(RUN_STEP_END)
|
||||||
} else {
|
} else if stepResult != nil {
|
||||||
log.Error().Str("step", stepName).
|
log.Error().Str("step", stepName).
|
||||||
Str("type", stepType).
|
Str("type", stepType).
|
||||||
Bool("success", false).
|
Bool("success", false).
|
||||||
Int64("elapsed(ms)", lastResult.Elapsed).
|
Int64("elapsed(ms)", stepResult.Elapsed).
|
||||||
|
Int("completed_tasks", len(stepResults)).
|
||||||
|
Int("total_tasks", len(tasks)).
|
||||||
Msg(RUN_STEP_END)
|
Msg(RUN_STEP_END)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// execute with loops as outer iteration
|
||||||
|
for _, task := range tasks {
|
||||||
|
// Check for interrupt signal before each parameter iteration
|
||||||
|
select {
|
||||||
|
case <-r.caseRunner.hrpRunner.interruptSignal:
|
||||||
|
log.Warn().Int("completed_tasks", len(stepResults)).
|
||||||
|
Int("total_tasks", len(tasks)).
|
||||||
|
Msg("interrupted during parameter iteration")
|
||||||
|
return nil, errors.Wrap(code.InterruptError, "parameter iteration interrupted")
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute step with merged variables
|
||||||
|
stepResult, stepErr := r.executeStepWithVariables(step, task.stepName, task.parameters)
|
||||||
|
if stepErr != nil {
|
||||||
|
if r.caseRunner.hrpRunner.failfast {
|
||||||
|
// failfast mode, abort running
|
||||||
|
return nil, errors.Wrap(stepErr, "execute step failed")
|
||||||
|
}
|
||||||
|
log.Error().Err(stepErr).Str("step", task.stepName).Msg("execute step failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
if stepResult != nil {
|
||||||
|
stepResults = append(stepResults, stepResult)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return last result
|
||||||
|
if len(stepResults) > 0 {
|
||||||
|
lastResult := stepResults[len(stepResults)-1]
|
||||||
return lastResult, nil
|
return lastResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user