diff options
author | Karthik Nayak <knayak@gitlab.com> | 2023-02-15 15:30:38 +0300 |
---|---|---|
committer | Karthik Nayak <knayak@gitlab.com> | 2023-02-17 13:19:03 +0300 |
commit | 5d56d59c16d548d6170e0d3c4263688fe00606c8 (patch) | |
tree | 163f4a1de905309ad781bbc3be5ae490d2c7e626 | |
parent | e4084894d8d74053dcdc97834d902f68a52bb3a4 (diff) |
gitaly: Apply hooks on each step
The `TestTransactionManager` only adds hooks when it first creates the
manager. This means if the manager was created in step X, the hooks from
step X+1 won't be added unless the manages is stopped/started. To avoid
this issue, we create a new `applyHooks` function and call this at the
beginning of each step.
-rw-r--r-- | internal/gitaly/transaction_manager_test.go | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/internal/gitaly/transaction_manager_test.go b/internal/gitaly/transaction_manager_test.go index 775e57796..de9ff8050 100644 --- a/internal/gitaly/transaction_manager_test.go +++ b/internal/gitaly/transaction_manager_test.go @@ -1507,6 +1507,18 @@ func TestTransactionManager(t *testing.T) { require.False(t, managerRunning) } + applyHooks := func(tb testing.TB, testHooks testHooks) { + installHooks(tb, transactionManager, database, repository, hooks{ + beforeReadLogEntry: testHooks.BeforeApplyLogEntry, + beforeResolveRevision: testHooks.BeforeAppendLogEntry, + beforeDeferredStop: func(hookContext) { + if testHooks.WaitForTransactionsWhenStopping { + inflightTransactions.Wait() + } + }, + }) + } + // startManager starts fresh manager and applies hooks into it. startManager := func(testHooks testHooks) { t.Helper() @@ -1516,15 +1528,7 @@ func TestTransactionManager(t *testing.T) { managerErr = make(chan error) transactionManager = NewTransactionManager(database, repository) - installHooks(t, transactionManager, database, repository, hooks{ - beforeResolveRevision: testHooks.BeforeAppendLogEntry, - beforeReadLogEntry: testHooks.BeforeApplyLogEntry, - beforeDeferredStop: func(hookContext) { - if testHooks.WaitForTransactionsWhenStopping { - inflightTransactions.Wait() - } - }, - }) + applyHooks(t, testHooks) go func() { managerErr <- transactionManager.Run() }() } @@ -1535,6 +1539,10 @@ func TestTransactionManager(t *testing.T) { // Ensure every step starts with the manager running. if !managerRunning { startManager(step.Hooks) + } else { + // Apply the hooks for this step if the manager is running already to ensure the + // steps hooks are in place. + applyHooks(t, step.Hooks) } if step.StopManager { |