diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-06-29 09:03:08 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-06-29 09:03:57 +0300 |
commit | 73f366b2d5029f3c6f77d9bd4a263d5037e627a1 (patch) | |
tree | 7913bf3fe17716fa5e2c915d8936548ec58407d6 | |
parent | 6585f1de3a73feb87d13618aa2e5d0d2109e4786 (diff) |
cmd/gitaly-hooks: Exercise transactions in test
We're about to default-enable transactional synchronization of hook
executions, which will cause both primary and secondary to cast an
additional vote after hooks have been executed by the primary node. This
will cause one of our tests in `cmd/gitaly-hooks` to fail because it
ain't got a transaction manager set up.
Prepare for this change by explicitly testing transactional logic, too.
-rw-r--r-- | cmd/gitaly-hooks/hooks_test.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index cebbccb09..8d44d2412 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -26,6 +26,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config/prometheus" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service/hook" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v16/internal/gitlab" "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/metadata" "gitlab.com/gitlab-org/gitaly/v16/internal/grpc/middleware/limithandler" @@ -356,6 +357,8 @@ func testHooksUpdate(t *testing.T, ctx context.Context, cfg config.Cfg, glValues } func TestHooksPostReceiveFailed(t *testing.T) { + t.Parallel() + secretToken := "secret token" glProtocol := "ssh" changes := "oldhead newhead" @@ -395,7 +398,9 @@ func TestHooksPostReceiveFailed(t *testing.T) { gitlabClient, err := gitlab.NewHTTPClient(logger, cfg.Gitlab, cfg.TLS, prometheus.Config{}) require.NoError(t, err) - runHookServiceWithGitlabClient(t, cfg, true, gitlabClient) + txManager := transaction.NewTrackingManager() + + runHookServiceWithGitlabClient(t, cfg, true, gitlabClient, testserver.WithTransactionManager(txManager)) customHookOutputPath := gittest.WriteEnvToCustomHook(t, repoPath, "post-receive") @@ -418,6 +423,7 @@ func TestHooksPostReceiveFailed(t *testing.T) { require.Empty(t, stdout.String()) require.Empty(t, stderr.String()) require.NoFileExists(t, customHookOutputPath) + require.Empty(t, txManager.Votes()) }, }, { @@ -430,12 +436,15 @@ func TestHooksPostReceiveFailed(t *testing.T) { require.Empty(t, stdout.String()) require.Empty(t, stderr.String()) require.NoFileExists(t, customHookOutputPath) + require.Empty(t, txManager.Votes()) }, }, } for _, tc := range testcases { t.Run(tc.desc, func(t *testing.T) { + txManager.Reset() + hooksPayload, err := git.NewHooksPayload( cfg, repo, |