Skip to content

Rename CreateProxyTxn to MaybeCreateProxyTxn #388

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

Merged
merged 1 commit into from
Apr 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion accumulator/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (b *Batch) finalizeInvocation(reqID, status string, time time.Time) error {
if !ok {
return fmt.Errorf("invocation for requestID %s does not exist", reqID)
}
proxyTxn, err := inc.CreateProxyTxn(status, time)
proxyTxn, err := inc.MaybeCreateProxyTxn(status, time)
if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions accumulator/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ func (inc *Invocation) NeedProxyTransaction() bool {
return !inc.Finalized && inc.TransactionID != "" && !inc.TransactionObserved
}

// CreateProxyTxn creates a proxy transaction for an invocation if required.
// A proxy transaction will be required to be created if the agent has
// registered a transaction for the invocation but has not sent the
// corresponding transaction to the extension.
func (inc *Invocation) CreateProxyTxn(status string, time time.Time) ([]byte, error) {
// MaybeCreateProxyTxn creates a proxy transaction for an invocation
// if required. A proxy transaction will be required to be created
// if the agent has registered a transaction for the invocation but
// has not sent the corresponding transaction to the extension. The
// proxy transaction will not be created if the invocation has
// already been finalized or the agent has reported the transaction.
func (inc *Invocation) MaybeCreateProxyTxn(status string, time time.Time) ([]byte, error) {
if !inc.NeedProxyTransaction() {
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions accumulator/invocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestCreateProxyTransaction(t *testing.T) {
AgentPayload: []byte(tc.payload),
TransactionObserved: tc.txnObserved,
}
result, err := inc.CreateProxyTxn(tc.runtimeDoneStatus, ts.Add(txnDur))
result, err := inc.MaybeCreateProxyTxn(tc.runtimeDoneStatus, ts.Add(txnDur))
assert.Nil(t, err)
if len(tc.output) > 0 {
assert.JSONEq(t, tc.output, string(result))
Expand All @@ -100,7 +100,7 @@ func TestCreateProxyTransaction(t *testing.T) {
}
}

func BenchmarkCreateProxyTxn(b *testing.B) {
func BenchmarkMaybeCreateProxyTxn(b *testing.B) {
ts := time.Date(2022, time.October, 1, 1, 0, 0, 0, time.UTC)
txnDur := ts.Add(time.Second)
inc := &Invocation{
Expand All @@ -114,7 +114,7 @@ func BenchmarkCreateProxyTxn(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := inc.CreateProxyTxn("success", txnDur)
_, err := inc.MaybeCreateProxyTxn("failure", txnDur)
if err != nil {
b.Fail()
}
Expand Down