-
Notifications
You must be signed in to change notification settings - Fork 67
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
Conversation
e0bf06e
to
cfdb822
Compare
There was a problem hiding this 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
} | ||
|
||
func (r PersistentTransactionRunner) waitTestRunIsFinished(ctx context.Context, testRun model.Run) (model.Run, error) { | ||
ticker := time.NewTicker(r.checkTestStateDelay) |
There was a problem hiding this comment.
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:
- instant updates, instead of depending on the polling interval. This also means more efficiency, since you just get the updates you need.
- No
r.db.GetRun
, you can use the channel to transmit the updated test run
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
return model.TransactionRun{}, fmt.Errorf("failed to marshal transaction steps: %w", err) | ||
} | ||
|
||
jsonStepRuns, err := json.Marshal(transactionRun.StepRuns) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
get: | ||
tags: | ||
- api | ||
parameters: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
cfdb822
to
ce593e6
Compare
server/model/transactions.go
Outdated
|
||
TransactionRunState string | ||
|
||
transactionStep struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transactionStep struct { | |
TransactionStep struct { |
server/model/transactions.go
Outdated
func (t Transaction) HasID() bool { | ||
return t.ID != "" | ||
} | ||
|
||
func NewTransactionRun(transaction Transaction) TransactionRun { | ||
testIds := make([]transactionStep, 0, len(transaction.Steps)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testIds := make([]transactionStep, 0, len(transaction.Steps)) | |
testIds := make([]TransactionStep, 0, len(transaction.Steps)) |
server/model/transactions.go
Outdated
testIds := make([]transactionStep, 0, len(transaction.Steps)) | ||
|
||
for _, test := range transaction.Steps { | ||
testIds = append(testIds, transactionStep{ID: test.ID, Name: test.Name}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testIds = append(testIds, transactionStep{ID: test.ID, Name: test.Name}) | |
testIds = append(testIds, TransactionStep{ID: test.ID, Name: test.Name}) |
There was a problem hiding this 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!
adf0f2c
to
82191d1
Compare
This PR adds endpoints for handling transaction runs and to execute a transaction
Checklist