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(frontend): add new test creation flow #3350

Merged
merged 18 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ server/html
docs/docs/cli/reference/

__debug*
web/cypress/downloads
16 changes: 16 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,22 @@ paths:
422:
description: could not stop execution, probably it's not running anymore

/tests/{testId}/run/{runId}/skipPolling:
post:
tags:
- api
parameters:
- $ref: "./parameters.yaml#/components/parameters/testId"
- $ref: "./parameters.yaml#/components/parameters/runId"
summary: "skips the trace collection of a test run"
description: "skips the trace collection of a test run"
operationId: skipTraceCollection
responses:
200:
description: successful operation
422:
description: could not stop execution, probably it's not running anymore

# Test events
/tests/{testId}/run/{runId}/events:
get:
Expand Down
3 changes: 3 additions & 0 deletions api/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ components:
format: date-time
trigger:
$ref: "./triggers.yaml#/components/schemas/Trigger"
skipTraceCollection:
type: boolean
description: If true, the test will not collect a trace
specs:
type: array
items:
Expand Down
96 changes: 96 additions & 0 deletions cli/openapi/api_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions cli/openapi/model_test_.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 41 additions & 12 deletions server/executor/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ func (q Queue) listenPreprocess(ctx context.Context, job Job) (context.Context,

ctx = context.WithValue(ctx, "LastInstanceID", job.Headers.Get("InstanceID"))

ctx, cancelCtx := context.WithCancel(ctx)
q.listenForStopRequests(context.Background(), cancelCtx, job)
ctx, cancelCtx := context.WithCancelCause(ctx)
q.listenForUserRequests(context.Background(), cancelCtx, job)

return ctx, Job{
Headers: job.Headers,
Expand All @@ -336,45 +336,74 @@ func (q Queue) listenPreprocess(ctx context.Context, job Job) (context.Context,
PollingProfile: q.resolvePollingProfile(ctx, job),
DataStore: q.resolveDataStore(ctx, job),
}

}

type StopRequest struct {
type UserRequestType string

var (
UserRequestTypeStop UserRequestType = "stop"
UserRequestSkipTraceCollection UserRequestType = "skip_trace_collection"
)

type UserRequest struct {
TestID id.ID
RunID int
}

func (sr StopRequest) ResourceID() string {
func (sr UserRequest) ResourceID(requestType UserRequestType) string {
runID := (test.Run{ID: sr.RunID, TestID: sr.TestID}).ResourceID()
return runID + "/stop"
return fmt.Sprintf("%s/%s", runID, requestType)
}

func (q Queue) listenForStopRequests(ctx context.Context, cancelCtx context.CancelFunc, job Job) {
var (
ErrSkipTraceCollection = errors.New("skip trace collection")
)

func (q Queue) listenForUserRequests(ctx context.Context, cancelCtx context.CancelCauseFunc, job Job) {
if q.subscriptor == nil {
return
}

sfn := subscription.NewSubscriberFunction(func(m subscription.Message) error {
cancelCtx()
stopRequest, ok := m.Content.(StopRequest)
cancelCtx(nil)
request, ok := m.Content.(UserRequest)
if !ok {
return nil
}

run, err := q.runs.GetRun(ctx, stopRequest.TestID, stopRequest.RunID)
run, err := q.runs.GetRun(ctx, request.TestID, request.RunID)
if err != nil {
return fmt.Errorf("failed to get run %d for test %s: %w", stopRequest.RunID, stopRequest.TestID, err)
return fmt.Errorf("failed to get run %d for test %s: %w", request.RunID, request.TestID, err)
}

if run.State == test.RunStateStopped {
return nil
}

return q.cancelRunHandlerFn(ctx, run)
})

spfn := subscription.NewSubscriberFunction(func(m subscription.Message) error {
request, ok := m.Content.(UserRequest)
if !ok {
return nil
}

run, err := q.runs.GetRun(ctx, request.TestID, request.RunID)
if err != nil {
return fmt.Errorf("failed to get run %d for test %s: %w", request.RunID, request.TestID, err)
}

if run.State == test.RunStateStopped || run.State.IsFinal() {
return nil
}

cancelCtx(ErrSkipTraceCollection)
return nil
})

q.subscriptor.Subscribe((StopRequest{job.Test.ID, job.Run.ID}).ResourceID(), sfn)
q.subscriptor.Subscribe((UserRequest{job.Test.ID, job.Run.ID}).ResourceID(UserRequestTypeStop), sfn)
q.subscriptor.Subscribe((UserRequest{job.Test.ID, job.Run.ID}).ResourceID(UserRequestSkipTraceCollection), spfn)
}

func (q Queue) resolveTestSuite(ctx context.Context, job Job) testsuite.TestSuite {
Expand Down
17 changes: 15 additions & 2 deletions server/executor/test_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (p *TestPipeline) Run(ctx context.Context, testObj test.Test, metadata test
requiredGates = &rg
}
run = run.ConfigureRequiredGates(*requiredGates)
run.SkipTraceCollection = testObj.SkipTraceCollection

run, err := p.runs.CreateRun(ctx, testObj, run)
p.handleDBError(run, err)
Expand Down Expand Up @@ -119,13 +120,25 @@ func (p *TestPipeline) Rerun(ctx context.Context, testObj test.Test, runID int)
}

func (p *TestPipeline) StopTest(ctx context.Context, testID id.ID, runID int) {
sr := StopRequest{
sr := UserRequest{
TestID: testID,
RunID: runID,
}

p.updatePublisher.PublishUpdate(subscription.Message{
ResourceID: sr.ResourceID(),
ResourceID: sr.ResourceID(UserRequestTypeStop),
Content: sr,
})
}

func (p *TestPipeline) SkipTraceCollection(ctx context.Context, testID id.ID, runID int) {
sr := UserRequest{
TestID: testID,
RunID: runID,
}

p.updatePublisher.PublishUpdate(subscription.Message{
ResourceID: sr.ResourceID(UserRequestSkipTraceCollection),
Content: sr,
})
}
Expand Down