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

feat(sever): for test runs, split the failed state into more descriptive statuses #2310

Merged
merged 4 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion server/executor/assertion_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (e *defaultAssertionRunner) runAssertionsAndUpdateResult(ctx context.Contex
log.Printf("[AssertionRunner] Test %s Run %d: fail to emit TestSpecsRunError event: %s\n", request.Test.ID, request.Run.ID, anotherErr.Error())
}

return model.Run{}, e.updater.Update(ctx, run.Failed(err))
return model.Run{}, e.updater.Update(ctx, run.AssertionFailed(err))
}
log.Printf("[AssertionRunner] Test %s Run %d: Success. pass: %d, fail: %d\n", request.Test.ID, request.Run.ID, run.Pass, run.Fail)

Expand Down
2 changes: 1 addition & 1 deletion server/executor/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (r persistentRunner) processExecQueue(job execReq) {
func (r persistentRunner) handleExecutionResult(run model.Run, response trigger.Response, err error) model.Run {
run = run.TriggerCompleted(response.Result)
if err != nil {
return run.Failed(err)
return run.TriggerFailed(err)
}

return run.SuccessfullyTriggered()
Expand Down
2 changes: 1 addition & 1 deletion server/executor/trace_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (tp tracePoller) handleTraceDBError(job PollingRequest, err error) {
fmt.Println("[TracePoller] Unknown error", err)
}

tp.handleDBError(tp.updater.Update(job.ctx, run.Failed(err)))
tp.handleDBError(tp.updater.Update(job.ctx, run.TraceFailed(err)))

tp.subscriptionManager.PublishUpdate(subscription.Message{
ResourceID: run.TransactionStepResourceID(),
Expand Down
4 changes: 2 additions & 2 deletions server/executor/transaction_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *fakeTestRunner) Run(ctx context.Context, test model.Test, metadata mode
time.Sleep(100 * time.Millisecond) // simulate some real work

if r.returnErr {
newRun.State = model.RunStateFailed
newRun.State = model.RunStateTriggerFailed
newRun.LastError = fmt.Errorf("failed to do something")
} else {
newRun.State = model.RunStateFinished
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestTransactionRunner(t *testing.T) {
runTransactionRunnerTest(t, true, func(t *testing.T, actual model.TransactionRun) {
assert.Equal(t, model.TransactionRunStateFailed, actual.State)
require.Len(t, actual.Steps, 1)
assert.Equal(t, model.RunStateFailed, actual.Steps[0].State)
assert.Equal(t, model.RunStateTriggerFailed, actual.Steps[0].State)
})
})

Expand Down
2 changes: 1 addition & 1 deletion server/model/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestRunEncoding(t *testing.T) {
ID: 1,
TraceID: tid,
SpanID: sid,
State: model.RunStateFailed,
State: model.RunStateTriggerFailed,
LastError: errors.New("some error"),
CreatedAt: t1,
ServiceTriggeredAt: t1,
Expand Down
16 changes: 14 additions & 2 deletions server/model/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,20 @@ func (r Run) Finish() Run {
return r
}

func (r Run) Failed(err error) Run {
r.State = RunStateFailed
func (r Run) TriggerFailed(err error) Run {
r.State = RunStateTriggerFailed
r.LastError = err
return r.Finish()
}

func (r Run) TraceFailed(err error) Run {
r.State = RunStateTraceFailed
r.LastError = err
return r.Finish()
}

func (r Run) AssertionFailed(err error) Run {
r.State = RunStateAssertionFailed
r.LastError = err
return r.Finish()
}
11 changes: 9 additions & 2 deletions server/model/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ const (
RunStateCreated RunState = "CREATED"
RunStateExecuting RunState = "EXECUTING"
RunStateAwaitingTrace RunState = "AWAITING_TRACE"
RunStateFailed RunState = "FAILED"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today we save this value on our database, right? How will we keep the retro compatibility with older Tracetest versions?
Should we map the old FAILED string as always ASSERTION_FAILED?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even writing a migration to fix it on the database?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't do a DB migration, it is too error prone. Fallbacking to another stata is better I think. Why do you suggest ASSERTION_FAILED? not that I have a better one, but to understand the logic of the choice.

RunStateTriggerFailed RunState = "TRIGGER_FAILED"
RunStateTraceFailed RunState = "TRACE_FAILED"
RunStateAssertionFailed RunState = "ASSERTION_FAILED"
RunStateFinished RunState = "FINISHED"
RunStateAwaitingTestResults RunState = "AWAITING_TEST_RESULTS"
)

func (rs RunState) IsFinal() bool {
return rs == RunStateFailed || rs == RunStateFinished
return rs.IsError() || rs == RunStateFinished
}

func (rs RunState) IsError() bool {
return rs == RunStateTriggerFailed ||
rs == RunStateTraceFailed
}

func (r Run) ResultsCount() (pass, fail int) {
Expand Down