Skip to content

Commit

Permalink
add Success to RunResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
rdubrock committed Oct 4, 2023
1 parent 867fb23 commit 0547651
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/k6runner/k6runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,17 @@ func (r Script) Run(ctx context.Context, registry *prometheus.Registry, logger l
var runResult error

result, scriptExited := k6runner.Run(ctx, r.script)
internalLogger.Debug().
Err(scriptExited).
Msg("k6 script exited with error code")

if scriptExited != nil {
runResult = scriptExited
internalLogger.Debug().
Err(scriptExited).
Msg("k6 script exited with error code")
}
if !result.Success {

if !result.Success && runResult == nil {
runResult = errors.New("finished run with errors")
}
// if err != nil {
// return err
// }

if err := textToRegistry(result.Metrics, registry, internalLogger); err != nil {
internalLogger.Debug().
Expand Down Expand Up @@ -415,7 +413,11 @@ func (r LocalRunner) Run(ctx context.Context, script []byte) (*RunResponse, erro
return nil, fmt.Errorf("cannot read logs: %w", err)
}

result.Success = true
if checkError == nil {
result.Success = true
} else {
result.Success = false
}

for _, log := range result.Logs {
if strings.Contains(string(log), "Assertion failed") {
Expand All @@ -425,7 +427,7 @@ func (r LocalRunner) Run(ctx context.Context, script []byte) (*RunResponse, erro

r.logger.Debug().Bytes("metrics", result.Metrics).Bytes("logs", result.Logs).Msg("k6 result")

return &result, checkError
return &result, nil
}

func mktemp(fs afero.Fs, dir, pattern string) (string, error) {
Expand Down

0 comments on commit 0547651

Please sign in to comment.