Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-04-29 09:20:51 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-04-29 13:21:58 +0300
commit324b407d56f892450614507ae97fb2d3e42c5455 (patch)
treededc4ff24ceeb74cdf820dcb3a6ed7b2acf734cb /internal/praefect/transaction_test.go
parentf706895a94fa2c73269db81643669c2cc2223314 (diff)
transactions: Rework cancellation interface
When registering transactions, the assumption is that the registering entity should also cancel the transaction at a later point in order to clean up any data associated with it. This assumption is currently not explicit in the API, and in fact we also delete the transaction when the single node taking part in the transaction calls the `StartTransaction` RPC. As a result, calling `CancelTransaction()` would result in an error. Improve the interface by removing `CancelTransaction()` and have `RegisterTransaction()` return a cancellation function, making it explicit that callers need to execute it.
Diffstat (limited to 'internal/praefect/transaction_test.go')
-rw-r--r--internal/praefect/transaction_test.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/internal/praefect/transaction_test.go b/internal/praefect/transaction_test.go
index a930532e3..4ca474fe1 100644
--- a/internal/praefect/transaction_test.go
+++ b/internal/praefect/transaction_test.go
@@ -39,9 +39,10 @@ func TestTransactionSucceeds(t *testing.T) {
client := gitalypb.NewRefTransactionClient(cc)
- transactionID, err := txMgr.RegisterTransaction([]string{"node1"})
+ transactionID, cancelTransaction, err := txMgr.RegisterTransaction([]string{"node1"})
require.NoError(t, err)
require.NotZero(t, transactionID)
+ defer cancelTransaction()
hash := sha1.Sum([]byte{})
@@ -58,7 +59,7 @@ func TestTransactionFailsWithMultipleNodes(t *testing.T) {
_, txMgr, cleanup := runPraefectWithTransactionMgr(t)
defer cleanup()
- _, err := txMgr.RegisterTransaction([]string{"node1", "node2"})
+ _, _, err := txMgr.RegisterTransaction([]string{"node1", "node2"})
require.Error(t, err)
}
@@ -90,11 +91,11 @@ func TestTransactionCancellation(t *testing.T) {
client := gitalypb.NewRefTransactionClient(cc)
- transactionID, err := txMgr.RegisterTransaction([]string{"node1"})
+ transactionID, cancelTransaction, err := txMgr.RegisterTransaction([]string{"node1"})
require.NoError(t, err)
require.NotZero(t, transactionID)
- require.NoError(t, txMgr.CancelTransaction(transactionID))
+ cancelTransaction()
hash := sha1.Sum([]byte{})
_, err = client.StartTransaction(ctx, &gitalypb.StartTransactionRequest{