|
1 | 1 | package runner
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "encoding/json"
|
5 | 6 | "fmt"
|
6 | 7 | "strconv"
|
@@ -56,6 +57,21 @@ func (ss *stepState) Started() bool {
|
56 | 57 | return ss.stepRunner.Started()
|
57 | 58 | }
|
58 | 59 |
|
| 60 | +func (ss *stepState) WaitResults(ctx context.Context) (stepResult StepResult, err error) { |
| 61 | + // should wait for stepState to process a possible error code from stepRunner |
| 62 | + select { |
| 63 | + case <-ctx.Done(): |
| 64 | + // Give priority to success path |
| 65 | + select { |
| 66 | + case <-ss.stopped: |
| 67 | + default: |
| 68 | + return StepResult{}, ctx.Err() |
| 69 | + } |
| 70 | + case <-ss.stopped: |
| 71 | + } |
| 72 | + return ss.stepRunner.WaitResults(ctx) |
| 73 | +} |
| 74 | + |
59 | 75 | func (ss *stepState) Stop() {
|
60 | 76 | ss.stepRunner.Stop()
|
61 | 77 | }
|
@@ -152,24 +168,24 @@ func (ss *stepState) String() string {
|
152 | 168 | return fmt.Sprintf("[#%d %s]", ss.stepIndex, ss.sb.TestStepLabel)
|
153 | 169 | }
|
154 | 170 |
|
155 |
| -func (ss *stepState) SetError(ctx xcontext.Context, err error) { |
| 171 | +func (ss *stepState) SetError(ctx xcontext.Context, runErr error) { |
156 | 172 | ss.mu.Lock()
|
157 | 173 | defer ss.mu.Unlock()
|
158 | 174 |
|
159 |
| - if err == nil || ss.runErr != nil { |
| 175 | + if runErr == nil || ss.runErr != nil { |
160 | 176 | return
|
161 | 177 | }
|
162 |
| - ctx.Errorf("Step '%s' failed with error: %v", ss.sb.TestStepLabel, err) |
163 |
| - ss.runErr = err |
| 178 | + ctx.Errorf("Step '%s' failed with error: %v", ss.sb.TestStepLabel, runErr) |
| 179 | + ss.runErr = runErr |
164 | 180 |
|
165 | 181 | if ss.runErr != xcontext.ErrPaused && ss.runErr != xcontext.ErrCanceled {
|
166 |
| - if err := emitEvent(ctx, ss.ev, EventTestError, nil, err.Error()); err != nil { |
| 182 | + if err := emitEvent(ctx, ss.ev, EventTestError, nil, runErr.Error()); err != nil { |
167 | 183 | ctx.Errorf("failed to emit event: %s", err)
|
168 | 184 | }
|
169 | 185 | }
|
170 | 186 |
|
171 | 187 | // notify last as callback may use GetError or cancel context
|
172 | 188 | go func() {
|
173 |
| - ss.onError(err) |
| 189 | + ss.onError(runErr) |
174 | 190 | }()
|
175 | 191 | }
|
0 commit comments