Skip to content

Commit cf9f5a3

Browse files
authored
Rename CreateProxyTxn to MaybeCreateProxyTxn (#388)
1 parent 02f4ef1 commit cf9f5a3

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

accumulator/batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (b *Batch) finalizeInvocation(reqID, status string, time time.Time) error {
311311
if !ok {
312312
return fmt.Errorf("invocation for requestID %s does not exist", reqID)
313313
}
314-
proxyTxn, err := inc.CreateProxyTxn(status, time)
314+
proxyTxn, err := inc.MaybeCreateProxyTxn(status, time)
315315
if err != nil {
316316
return err
317317
}

accumulator/invocation.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ func (inc *Invocation) NeedProxyTransaction() bool {
5757
return !inc.Finalized && inc.TransactionID != "" && !inc.TransactionObserved
5858
}
5959

60-
// CreateProxyTxn creates a proxy transaction for an invocation if required.
61-
// A proxy transaction will be required to be created if the agent has
62-
// registered a transaction for the invocation but has not sent the
63-
// corresponding transaction to the extension.
64-
func (inc *Invocation) CreateProxyTxn(status string, time time.Time) ([]byte, error) {
60+
// MaybeCreateProxyTxn creates a proxy transaction for an invocation
61+
// if required. A proxy transaction will be required to be created
62+
// if the agent has registered a transaction for the invocation but
63+
// has not sent the corresponding transaction to the extension. The
64+
// proxy transaction will not be created if the invocation has
65+
// already been finalized or the agent has reported the transaction.
66+
func (inc *Invocation) MaybeCreateProxyTxn(status string, time time.Time) ([]byte, error) {
6567
if !inc.NeedProxyTransaction() {
6668
return nil, nil
6769
}

accumulator/invocation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestCreateProxyTransaction(t *testing.T) {
8989
AgentPayload: []byte(tc.payload),
9090
TransactionObserved: tc.txnObserved,
9191
}
92-
result, err := inc.CreateProxyTxn(tc.runtimeDoneStatus, ts.Add(txnDur))
92+
result, err := inc.MaybeCreateProxyTxn(tc.runtimeDoneStatus, ts.Add(txnDur))
9393
assert.Nil(t, err)
9494
if len(tc.output) > 0 {
9595
assert.JSONEq(t, tc.output, string(result))
@@ -100,7 +100,7 @@ func TestCreateProxyTransaction(t *testing.T) {
100100
}
101101
}
102102

103-
func BenchmarkCreateProxyTxn(b *testing.B) {
103+
func BenchmarkMaybeCreateProxyTxn(b *testing.B) {
104104
ts := time.Date(2022, time.October, 1, 1, 0, 0, 0, time.UTC)
105105
txnDur := ts.Add(time.Second)
106106
inc := &Invocation{
@@ -114,7 +114,7 @@ func BenchmarkCreateProxyTxn(b *testing.B) {
114114
b.ReportAllocs()
115115
b.ResetTimer()
116116
for i := 0; i < b.N; i++ {
117-
_, err := inc.CreateProxyTxn("success", txnDur)
117+
_, err := inc.MaybeCreateProxyTxn("failure", txnDur)
118118
if err != nil {
119119
b.Fail()
120120
}

0 commit comments

Comments
 (0)