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: transaction run crud and execution #1465

Merged
merged 25 commits into from
Nov 14, 2022
Merged

Conversation

mathnogueira
Copy link
Member

This PR adds endpoints for handling transaction runs and to execute a transaction

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

Copy link
Collaborator

@schoren schoren left a comment

Choose a reason for hiding this comment

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

The basic idea of the runner looks fine, but there are a few things that needs to be fixed for the app to keep consistent behaviour (such as order of things) and performance

server/executor/transaction_runner.go Outdated Show resolved Hide resolved
}

func (r PersistentTransactionRunner) waitTestRunIsFinished(ctx context.Context, testRun model.Run) (model.Run, error) {
ticker := time.NewTicker(r.checkTestStateDelay)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not a great mechanism. Everything is within the same process here, so you could easily use channels to have a reactive model. This would yield 2 benefits:

  1. instant updates, instead of depending on the polling interval. This also means more efficiency, since you just get the updates you need.
  2. No r.db.GetRun, you can use the channel to transmit the updated test run

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented it.

)

func (rs TransactionRunState) IsFinal() bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it neccesary to have a separated type for transaction's run state? can't we share the same with the tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to have a different state because some states in the test state don't make sense for transactions, such as AWAITING_TRACE

server/executor/transaction_runner.go Outdated Show resolved Hide resolved
return model.TransactionRun{}, fmt.Errorf("failed to marshal transaction steps: %w", err)
}

jsonStepRuns, err := json.Marshal(transactionRun.StepRuns)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like it's gonna hold A LOT of data that already exists on the test_runs table. I would rather see an FK here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now it keeps simpler objects containing only the essentials for running the transaction


type (
Environment struct {
ID string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is this being persisted?

Name string
Description string
CreatedAt time.Time
Values []EnvironmentValue
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be a map[string]string? maybe an OrderedMap?

Copy link
Member Author

Choose a reason for hiding this comment

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

The order of environments doesn't matter, so no need for OrderedMap. map[string]string might be a better alternative than an array.

}

func (e Environment) Merge(env Environment) Environment {
values := make(map[string]string)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the idea of this is to avoid duplicated env keys. but in doing this, it's loosing the order guaranteed in a slice, which I imagine is the point of e.Values being a slice.

The only way to keep order and uniqueness of a map is using OrderedMap, even if the code looks a bit to verbose

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, the order doesn't matter in this case. I'll change it to map[string]string in a different PR

assert.Contains(t, newEnv.Values, model.EnvironmentValue{Key: "URL", Value: "http://localhost"})
assert.Contains(t, newEnv.Values, model.EnvironmentValue{Key: "PORT", Value: "8085"})
assert.Contains(t, newEnv.Values, model.EnvironmentValue{Key: "apiKey", Value: "abcdef"})
assert.Contains(t, newEnv.Values, model.EnvironmentValue{Key: "apiKeyLocation", Value: "header"})
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be nice to have an override key in this test

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if the idea of having an array is to keep the order, it would be great to have a test to guarantee the ordering

@@ -233,82 +233,3 @@ func TestGetTransactionsWithMultipleVersions(t *testing.T) {
assert.Equal(t, 2, test.Version)
}
}

// func TestTransactionSummary(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can all this commented code be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

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

I forgot to remove it in my old PR. We don't have transaction summaries yet, so I decided to remove it and reintroduce it later.

api/openapi.yaml Outdated Show resolved Hide resolved
get:
tags:
- api
parameters:
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be helpful to have the take and skip params here to support pagination.

Copy link
Member Author

Choose a reason for hiding this comment

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

makes sense. I'll add this in another PR, this is way too big already


TransactionRunState string

transactionStep struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
transactionStep struct {
TransactionStep struct {

func (t Transaction) HasID() bool {
return t.ID != ""
}

func NewTransactionRun(transaction Transaction) TransactionRun {
testIds := make([]transactionStep, 0, len(transaction.Steps))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
testIds := make([]transactionStep, 0, len(transaction.Steps))
testIds := make([]TransactionStep, 0, len(transaction.Steps))

testIds := make([]transactionStep, 0, len(transaction.Steps))

for _, test := range transaction.Steps {
testIds = append(testIds, transactionStep{ID: test.ID, Name: test.Name})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
testIds = append(testIds, transactionStep{ID: test.ID, Name: test.Name})
testIds = append(testIds, TransactionStep{ID: test.ID, Name: test.Name})

Copy link
Collaborator

@schoren schoren left a comment

Choose a reason for hiding this comment

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

Looks awesome! thanks for addressing everything!

@mathnogueira mathnogueira merged commit aaad0b7 into main Nov 14, 2022
@mathnogueira mathnogueira deleted the feat/transaction-run branch November 14, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants