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:
authorSami Hiltunen <shiltunen@gitlab.com>2022-01-28 16:16:26 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-02-02 14:24:22 +0300
commitbf952762c181c43976348ca6528d5c1405d8c5ee (patch)
treef84333eaf3ea36a57212e5e6747e7d048ba3305b
parentacaad3637701826dacac0c394411f3beb8cfe9c7 (diff)
Propagate test context to setup helpers in repository package
setupRepositoryService is currently using a TODO context. This commit propagates the test context down from the tests to the setup helper.
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes_test.go4
-rw-r--r--internal/gitaly/service/repository/archive_test.go12
-rw-r--r--internal/gitaly/service/repository/backup_custom_hooks_test.go6
-rw-r--r--internal/gitaly/service/repository/calculate_checksum_test.go14
-rw-r--r--internal/gitaly/service/repository/cleanup_test.go8
-rw-r--r--internal/gitaly/service/repository/commit_graph_test.go19
-rw-r--r--internal/gitaly/service/repository/create_bundle_from_ref_list_test.go9
-rw-r--r--internal/gitaly/service/repository/create_bundle_test.go3
-rw-r--r--internal/gitaly/service/repository/create_fork_test.go2
-rw-r--r--internal/gitaly/service/repository/create_repository_from_bundle_test.go4
-rw-r--r--internal/gitaly/service/repository/create_repository_from_url_test.go2
-rw-r--r--internal/gitaly/service/repository/fetch_bundle_test.go5
-rw-r--r--internal/gitaly/service/repository/fetch_remote_test.go33
-rw-r--r--internal/gitaly/service/repository/fetch_test.go12
-rw-r--r--internal/gitaly/service/repository/fsck_test.go6
-rw-r--r--internal/gitaly/service/repository/gc_test.go32
-rw-r--r--internal/gitaly/service/repository/info_attributes_test.go14
-rw-r--r--internal/gitaly/service/repository/merge_base_test.go9
-rw-r--r--internal/gitaly/service/repository/midx_test.go11
-rw-r--r--internal/gitaly/service/repository/optimize_test.go10
-rw-r--r--internal/gitaly/service/repository/raw_changes_test.go25
-rw-r--r--internal/gitaly/service/repository/remove_test.go2
-rw-r--r--internal/gitaly/service/repository/rename_test.go4
-rw-r--r--internal/gitaly/service/repository/repack_test.go16
-rw-r--r--internal/gitaly/service/repository/repository_test.go3
-rw-r--r--internal/gitaly/service/repository/restore_custom_hooks_test.go6
-rw-r--r--internal/gitaly/service/repository/search_files_test.go6
-rw-r--r--internal/gitaly/service/repository/size_test.go10
-rw-r--r--internal/gitaly/service/repository/snapshot_test.go8
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go8
-rw-r--r--internal/gitaly/service/repository/write_ref_test.go9
31 files changed, 177 insertions, 135 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go
index a5a34d181..f7ecfbb70 100644
--- a/internal/gitaly/service/repository/apply_gitattributes_test.go
+++ b/internal/gitaly/service/repository/apply_gitattributes_test.go
@@ -29,7 +29,7 @@ func TestApplyGitattributesSuccess(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, _, client := setupRepositoryService(t)
+ cfg, repo, _, client := setupRepositoryService(ctx, t)
infoPath := filepath.Join(cfg.Storages[0].Path, repo.GetRelativePath(), "info")
attributesPath := filepath.Join(infoPath, "attributes")
@@ -217,7 +217,7 @@ func TestApplyGitattributesFailure(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
tests := []struct {
repo *gitalypb.Repository
diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go
index 6316a14c3..ac8f32de0 100644
--- a/internal/gitaly/service/repository/archive_test.go
+++ b/internal/gitaly/service/repository/archive_test.go
@@ -32,7 +32,8 @@ const (
func TestGetArchiveSuccess(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
formats := []gitalypb.GetArchiveRequest_Format{
gitalypb.GetArchiveRequest_ZIP,
@@ -131,8 +132,6 @@ func TestGetArchiveSuccess(t *testing.T) {
for _, format := range formats {
testCaseName := fmt.Sprintf("%s-%s", tc.desc, format.String())
t.Run(testCaseName, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
req := &gitalypb.GetArchiveRequest{
Repository: repo,
CommitId: tc.commitID,
@@ -282,7 +281,8 @@ func TestGetArchiveWithLfsSuccess(t *testing.T) {
func TestGetArchiveFailure(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
commitID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
@@ -387,8 +387,6 @@ func TestGetArchiveFailure(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
req := &gitalypb.GetArchiveRequest{
Repository: tc.repo,
CommitId: tc.commitID,
@@ -409,8 +407,8 @@ func TestGetArchiveFailure(t *testing.T) {
func TestGetArchivePathInjection(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryServiceWithWorktree(t)
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryServiceWithWorktree(ctx, t)
// Adding a temp directory representing the .ssh directory
sshDirectory := testhelper.TempDir(t)
diff --git a/internal/gitaly/service/repository/backup_custom_hooks_test.go b/internal/gitaly/service/repository/backup_custom_hooks_test.go
index 39706cf24..8582ddd6d 100644
--- a/internal/gitaly/service/repository/backup_custom_hooks_test.go
+++ b/internal/gitaly/service/repository/backup_custom_hooks_test.go
@@ -17,8 +17,8 @@ import (
func TestSuccessfullBackupCustomHooksRequest(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
expectedTarResponse := []string{
"custom_hooks/",
@@ -55,8 +55,8 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) {
func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
linkTarget := "/var/empty"
require.NoError(t, os.Symlink(linkTarget, filepath.Join(repoPath, "custom_hooks")), "Could not create custom_hooks symlink")
@@ -83,8 +83,8 @@ func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) {
func TestSuccessfullBackupCustomHooksRequestWithNoHooks(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
backupRequest := &gitalypb.BackupCustomHooksRequest{Repository: repo}
backupStream, err := client.BackupCustomHooks(ctx, backupRequest)
diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go
index 5b18020ee..7762742f3 100644
--- a/internal/gitaly/service/repository/calculate_checksum_test.go
+++ b/internal/gitaly/service/repository/calculate_checksum_test.go
@@ -16,7 +16,9 @@ import (
func TestSuccessfulCalculateChecksum(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
// Force the refs database of testRepo into a known state
require.NoError(t, os.RemoveAll(filepath.Join(repoPath, "refs")))
@@ -28,9 +30,8 @@ func TestSuccessfulCalculateChecksum(t *testing.T) {
gittest.Exec(t, cfg, "-C", repoPath, "symbolic-ref", "HEAD", "refs/heads/feature")
request := &gitalypb.CalculateChecksumRequest{Repository: repo}
- testCtx := testhelper.Context(t)
- response, err := client.CalculateChecksum(testCtx, request)
+ response, err := client.CalculateChecksum(ctx, request)
require.NoError(t, err)
require.Equal(t, "0c500d7c8a9dbf65e4cf5e58914bec45bfb6e9ab", response.Checksum)
}
@@ -98,7 +99,9 @@ func TestFailedCalculateChecksum(t *testing.T) {
func TestInvalidRefsCalculateChecksum(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
// Force the refs database of testRepo into a known state
require.NoError(t, os.RemoveAll(filepath.Join(repoPath, "refs")))
@@ -108,9 +111,8 @@ func TestInvalidRefsCalculateChecksum(t *testing.T) {
require.NoError(t, exec.Command("cp", "testdata/checksum-test-invalid-refs", filepath.Join(repoPath, "packed-refs")).Run())
request := &gitalypb.CalculateChecksumRequest{Repository: repo}
- testCtx := testhelper.Context(t)
- response, err := client.CalculateChecksum(testCtx, request)
+ response, err := client.CalculateChecksum(ctx, request)
require.NoError(t, err)
require.Equal(t, git.ZeroOID.String(), response.Checksum)
}
diff --git a/internal/gitaly/service/repository/cleanup_test.go b/internal/gitaly/service/repository/cleanup_test.go
index 4a5dfd314..215a57b11 100644
--- a/internal/gitaly/service/repository/cleanup_test.go
+++ b/internal/gitaly/service/repository/cleanup_test.go
@@ -81,7 +81,8 @@ func TestCleanupDeletesStaleWorktrees(t *testing.T) {
func TestCleanupDeletesOrphanedWorktrees(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
worktreeCheckoutPath := filepath.Join(repoPath, worktreePrefix, "test-worktree")
basePath := filepath.Join(repoPath, "worktrees")
@@ -89,7 +90,6 @@ func TestCleanupDeletesOrphanedWorktrees(t *testing.T) {
require.NoError(t, os.MkdirAll(worktreeCheckoutPath, os.ModePerm))
require.NoError(t, os.Chtimes(worktreeCheckoutPath, oldTreeTime, oldTreeTime))
- ctx := testhelper.Context(t)
c, err := client.Cleanup(ctx, &gitalypb.CleanupRequest{Repository: repo})
assert.NoError(t, err)
@@ -108,7 +108,8 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) {
worktreeAdminDir = "worktrees"
)
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
worktreePath := filepath.Join(repoPath, worktreePrefix, worktreeName)
worktreeAdminPath := filepath.Join(
@@ -118,7 +119,6 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) {
req := &gitalypb.CleanupRequest{Repository: repo}
gittest.AddWorktree(t, cfg, repoPath, worktreePath)
- ctx := testhelper.Context(t)
// removing the work tree path but leaving the administrative files in
// $GIT_DIR/worktrees will result in the work tree being in a
diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go
index e87a7bbce..cebab071d 100644
--- a/internal/gitaly/service/repository/commit_graph_test.go
+++ b/internal/gitaly/service/repository/commit_graph_test.go
@@ -20,7 +20,9 @@ import (
func TestWriteCommitGraph_withExistingCommitGraphCreatedWithDefaults(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
commitGraphPath := filepath.Join(repoPath, stats.CommitGraphRelPath)
require.NoError(t, os.RemoveAll(commitGraphPath))
@@ -40,7 +42,6 @@ func TestWriteCommitGraph_withExistingCommitGraphCreatedWithDefaults(t *testing.
gittest.WithBranch(t.Name()),
gittest.WithTreeEntries(treeEntry),
)
- ctx := testhelper.Context(t)
res, err := client.WriteCommitGraph(ctx, &gitalypb.WriteCommitGraphRequest{
Repository: repo,
@@ -56,7 +57,9 @@ func TestWriteCommitGraph_withExistingCommitGraphCreatedWithDefaults(t *testing.
func TestWriteCommitGraph_withExistingCommitGraphCreatedWithSplit(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
commitGraphPath := filepath.Join(repoPath, stats.CommitGraphRelPath)
require.NoError(t, os.RemoveAll(commitGraphPath))
@@ -76,7 +79,6 @@ func TestWriteCommitGraph_withExistingCommitGraphCreatedWithSplit(t *testing.T)
gittest.WithBranch(t.Name()),
gittest.WithTreeEntries(treeEntry),
)
- ctx := testhelper.Context(t)
res, err := client.WriteCommitGraph(ctx, &gitalypb.WriteCommitGraphRequest{
Repository: repo,
@@ -92,8 +94,9 @@ func TestWriteCommitGraph_withExistingCommitGraphCreatedWithSplit(t *testing.T)
func TestWriteCommitGraph(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
chainPath := filepath.Join(repoPath, stats.CommitGraphChainRelPath)
@@ -111,8 +114,9 @@ func TestWriteCommitGraph(t *testing.T) {
func TestWriteCommitGraph_validationChecks(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t, testserver.WithDisablePraefect())
+
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t, testserver.WithDisablePraefect())
for _, tc := range []struct {
desc string
@@ -147,8 +151,9 @@ func TestWriteCommitGraph_validationChecks(t *testing.T) {
func TestUpdateCommitGraph(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
chainPath := filepath.Join(repoPath, stats.CommitGraphChainRelPath)
require.NoFileExists(t, chainPath)
diff --git a/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go b/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go
index 1e99580f7..54c24db7d 100644
--- a/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go
+++ b/internal/gitaly/service/repository/create_bundle_from_ref_list_test.go
@@ -19,8 +19,9 @@ import (
func TestCreateBundleFromRefList_success(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
// Create a work tree with a HEAD pointing to a commit that is missing. CreateBundle should
// clean this up before creating the bundle.
@@ -68,7 +69,9 @@ func TestCreateBundleFromRefList_success(t *testing.T) {
func TestCreateBundleFromRefList_validations(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
@@ -97,8 +100,6 @@ func TestCreateBundleFromRefList_validations(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
stream, err := client.CreateBundleFromRefList(ctx)
require.NoError(t, err)
diff --git a/internal/gitaly/service/repository/create_bundle_test.go b/internal/gitaly/service/repository/create_bundle_test.go
index dbf5b7fd4..de98f8bec 100644
--- a/internal/gitaly/service/repository/create_bundle_test.go
+++ b/internal/gitaly/service/repository/create_bundle_test.go
@@ -19,8 +19,9 @@ import (
func TestSuccessfulCreateBundleRequest(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
// Create a work tree with a HEAD pointing to a commit that is missing. CreateBundle should
// clean this up before creating the bundle.
diff --git a/internal/gitaly/service/repository/create_fork_test.go b/internal/gitaly/service/repository/create_fork_test.go
index f5c080942..841f64088 100644
--- a/internal/gitaly/service/repository/create_fork_test.go
+++ b/internal/gitaly/service/repository/create_fork_test.go
@@ -219,7 +219,7 @@ func TestCreateFork_targetExists(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- cfg, repo, _, client := setupRepositoryService(t)
+ cfg, repo, _, client := setupRepositoryService(ctx, t)
ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
diff --git a/internal/gitaly/service/repository/create_repository_from_bundle_test.go b/internal/gitaly/service/repository/create_repository_from_bundle_test.go
index 9989aca34..90772615b 100644
--- a/internal/gitaly/service/repository/create_repository_from_bundle_test.go
+++ b/internal/gitaly/service/repository/create_repository_from_bundle_test.go
@@ -31,7 +31,7 @@ func TestCreateRepositoryFromBundle_successful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
locator := config.NewLocator(cfg)
tmpdir, err := tempdir.New(ctx, repo.GetStorageName(), locator)
@@ -96,7 +96,7 @@ func TestCreateRepositoryFromBundle_transactional(t *testing.T) {
txManager := transaction.NewTrackingManager()
- cfg, repoProto, repoPath, client := setupRepositoryService(t, testserver.WithTransactionManager(txManager))
+ cfg, repoProto, repoPath, client := setupRepositoryService(ctx, t, testserver.WithTransactionManager(txManager))
// Reset the votes casted while creating the test repository.
txManager.Reset()
diff --git a/internal/gitaly/service/repository/create_repository_from_url_test.go b/internal/gitaly/service/repository/create_repository_from_url_test.go
index ad6c40349..40bd8f56b 100644
--- a/internal/gitaly/service/repository/create_repository_from_url_test.go
+++ b/internal/gitaly/service/repository/create_repository_from_url_test.go
@@ -23,7 +23,7 @@ func TestCreateRepotitoryFromURL_successful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, _, repoPath, client := setupRepositoryService(t)
+ cfg, _, repoPath, client := setupRepositoryService(ctx, t)
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
importedRepo := &gitalypb.Repository{
diff --git a/internal/gitaly/service/repository/fetch_bundle_test.go b/internal/gitaly/service/repository/fetch_bundle_test.go
index 550d8d48a..424e963ca 100644
--- a/internal/gitaly/service/repository/fetch_bundle_test.go
+++ b/internal/gitaly/service/repository/fetch_bundle_test.go
@@ -26,7 +26,9 @@ import (
func TestServer_FetchBundle_success(t *testing.T) {
t.Parallel()
- cfg, _, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, _, repoPath, client := setupRepositoryService(ctx, t)
tmp := testhelper.TempDir(t)
bundlePath := filepath.Join(tmp, "test.bundle")
@@ -35,7 +37,6 @@ func TestServer_FetchBundle_success(t *testing.T) {
gittest.Exec(t, cfg, "-C", repoPath, "bundle", "create", bundlePath, "--all")
expectedRefs := gittest.Exec(t, cfg, "-C", repoPath, "show-ref", "--head")
- ctx := testhelper.Context(t)
targetRepo, targetRepoPath := gittest.CreateRepository(ctx, t, cfg)
stream, err := client.FetchBundle(ctx)
diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go
index 7fc2cec45..a03761f98 100644
--- a/internal/gitaly/service/repository/fetch_remote_test.go
+++ b/internal/gitaly/service/repository/fetch_remote_test.go
@@ -33,8 +33,8 @@ import (
func TestFetchRemoteSuccess(t *testing.T) {
t.Parallel()
- cfg, _, repoPath, client := setupRepositoryService(t)
ctx := testhelper.Context(t)
+ cfg, _, repoPath, client := setupRepositoryService(ctx, t)
cloneRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
Seed: gittest.SeedGitLabTest,
@@ -132,12 +132,13 @@ func TestFetchRemote_sshCommand(t *testing.T) {
func TestFetchRemote_withDefaultRefmaps(t *testing.T) {
t.Parallel()
- cfg, sourceRepoProto, sourceRepoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, sourceRepoProto, sourceRepoPath, client := setupRepositoryService(ctx, t)
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
sourceRepo := localrepo.NewTestRepo(t, cfg, sourceRepoProto)
- ctx := testhelper.Context(t)
targetRepoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
Seed: gittest.SeedGitLabTest,
})
@@ -221,9 +222,10 @@ func TestFetchRemote_transaction(t *testing.T) {
func TestFetchRemote_prune(t *testing.T) {
t.Parallel()
- cfg, _, sourceRepoPath, client := setupRepositoryService(t)
- gitCmdFactory := gittest.NewCommandFactory(t, cfg)
+
ctx := testhelper.Context(t)
+ cfg, _, sourceRepoPath, client := setupRepositoryService(ctx, t)
+ gitCmdFactory := gittest.NewCommandFactory(t, cfg)
port, stopGitServer := gittest.HTTPServer(ctx, t, gitCmdFactory, sourceRepoPath, nil)
defer func() { require.NoError(t, stopGitServer()) }()
@@ -297,7 +299,7 @@ func TestFetchRemote_force(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, sourceRepoProto, sourceRepoPath, client := setupRepositoryService(t)
+ cfg, sourceRepoProto, sourceRepoPath, client := setupRepositoryService(ctx, t)
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
sourceRepo := localrepo.NewTestRepo(t, cfg, sourceRepoProto)
@@ -440,12 +442,13 @@ func TestFetchRemote_force(t *testing.T) {
func TestFetchRemoteFailure(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
const remoteName = "test-repo"
httpSrv, _ := remoteHTTPServer(t, remoteName, httpToken)
defer httpSrv.Close()
- ctx := testhelper.Context(t)
tests := []struct {
desc string
@@ -577,8 +580,9 @@ func getRefnames(t *testing.T, cfg config.Cfg, repoPath string) []string {
func TestFetchRemoteOverHTTP(t *testing.T) {
t.Parallel()
- cfg, _, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, _, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
description string
@@ -633,8 +637,9 @@ func TestFetchRemoteOverHTTP(t *testing.T) {
func TestFetchRemoteWithPath(t *testing.T) {
t.Parallel()
- cfg, _, sourceRepoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, _, sourceRepoPath, client := setupRepositoryService(ctx, t)
mirrorRepo, mirrorRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
Seed: gittest.SeedGitLabTest,
@@ -653,7 +658,9 @@ func TestFetchRemoteWithPath(t *testing.T) {
func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
s := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -662,7 +669,6 @@ func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) {
}),
)
defer s.Close()
- ctx := testhelper.Context(t)
req := &gitalypb.FetchRemoteRequest{
Repository: repo,
@@ -677,8 +683,9 @@ func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) {
func TestFetchRemoteOverHTTPWithTimeout(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
ctx, cancel := context.WithCancel(testhelper.Context(t))
+ _, repo, _, client := setupRepositoryService(ctx, t)
s := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go
index db35fd4b6..360ced75d 100644
--- a/internal/gitaly/service/repository/fetch_test.go
+++ b/internal/gitaly/service/repository/fetch_test.go
@@ -15,8 +15,9 @@ import (
func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
t.Parallel()
- cfg, sourceRepo, sourcePath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, sourceRepo, sourcePath, client := setupRepositoryService(ctx, t)
md := testcfg.GitalyServersMetadataFromCfg(t, cfg)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
@@ -48,8 +49,9 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
t.Parallel()
- cfg, repoProto, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRepositoryService(ctx, t)
md := testcfg.GitalyServersMetadataFromCfg(t, cfg)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
@@ -78,8 +80,9 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
func TestFetchSourceBranchBranchNotFound(t *testing.T) {
t.Parallel()
- cfg, targetRepo, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, targetRepo, _, client := setupRepositoryService(ctx, t)
md := testcfg.GitalyServersMetadataFromCfg(t, cfg)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
@@ -126,8 +129,9 @@ func TestFetchSourceBranchBranchNotFound(t *testing.T) {
func TestFetchSourceBranchWrongRef(t *testing.T) {
t.Parallel()
- cfg, targetRepo, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, targetRepo, _, client := setupRepositoryService(ctx, t)
md := testcfg.GitalyServersMetadataFromCfg(t, cfg)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go
index 981703ab4..307578306 100644
--- a/internal/gitaly/service/repository/fsck_test.go
+++ b/internal/gitaly/service/repository/fsck_test.go
@@ -16,7 +16,7 @@ func TestFsckSuccess(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
c, err := client.Fsck(ctx, &gitalypb.FsckRequest{Repository: repo})
assert.NoError(t, err)
@@ -28,7 +28,7 @@ func TestFsckFailureSeverelyBrokenRepo(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, repoPath, client := setupRepositoryService(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
// This makes the repo severely broken so that `git` does not identify it as a
// proper repo.
@@ -47,7 +47,7 @@ func TestFsckFailureSlightlyBrokenRepo(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, repoPath, client := setupRepositoryService(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
// This makes the repo slightly broken so that `git` still identify it as a
// proper repo, but `fsck` complains about broken refs...
diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go
index 340145b6f..c5821540d 100644
--- a/internal/gitaly/service/repository/gc_test.go
+++ b/internal/gitaly/service/repository/gc_test.go
@@ -28,8 +28,9 @@ var (
func TestGarbageCollectCommitGraph(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
c, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: repo})
assert.NoError(t, err)
@@ -41,7 +42,9 @@ func TestGarbageCollectCommitGraph(t *testing.T) {
func TestGarbageCollectSuccess(t *testing.T) {
t.Parallel()
- cfg, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repo, _, client := setupRepositoryService(ctx, t)
tests := []struct {
req *gitalypb.GarbageCollectRequest
@@ -65,7 +68,6 @@ func TestGarbageCollectSuccess(t *testing.T) {
// precision on `mtime`.
// Stamp taken from https://golang.org/pkg/time/#pkg-constants
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, packPath)
- ctx := testhelper.Context(t)
c, err := client.GarbageCollect(ctx, test.req)
assert.NoError(t, err)
assert.NotNil(t, c)
@@ -94,7 +96,7 @@ func TestGarbageCollectWithPrune(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
blobHashes := gittest.WriteBlobs(t, cfg, repoPath, 3)
oldDanglingObjFile := filepath.Join(repoPath, "objects", blobHashes[0][:2], blobHashes[0][2:])
@@ -136,7 +138,7 @@ func TestGarbageCollectLogStatistics(t *testing.T) {
ctx := testhelper.Context(t)
logger, hook := test.NewNullLogger()
- _, repo, _, client := setupRepositoryService(t, testserver.WithLogger(logger))
+ _, repo, _, client := setupRepositoryService(ctx, t, testserver.WithLogger(logger))
_, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: repo})
require.NoError(t, err)
@@ -146,8 +148,9 @@ func TestGarbageCollectLogStatistics(t *testing.T) {
func TestGarbageCollectDeletesRefsLocks(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
req := &gitalypb.GarbageCollectRequest{Repository: repo}
refsPath := filepath.Join(repoPath, "refs")
@@ -252,8 +255,9 @@ func TestGarbageCollectDeletesPackedRefsLock(t *testing.T) {
func TestGarbageCollectDeletesFileLocks(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
req := &gitalypb.GarbageCollectRequest{Repository: repo}
@@ -339,7 +343,9 @@ func TestGarbageCollectDeletesPackedRefsNew(t *testing.T) {
func TestGarbageCollectFailure(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
tests := []struct {
repo *gitalypb.Repository
@@ -353,7 +359,6 @@ func TestGarbageCollectFailure(t *testing.T) {
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.repo), func(t *testing.T) {
- ctx := testhelper.Context(t)
_, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: test.repo})
testhelper.RequireGrpcCode(t, err, test.code)
})
@@ -362,7 +367,9 @@ func TestGarbageCollectFailure(t *testing.T) {
func TestCleanupInvalidKeepAroundRefs(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
// Make the directory, so we can create random reflike things in it
require.NoError(t, os.MkdirAll(filepath.Join(repoPath, "refs", "keep-around"), 0o755))
@@ -407,8 +414,6 @@ func TestCleanupInvalidKeepAroundRefs(t *testing.T) {
for _, testcase := range testCases {
t.Run(testcase.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
// Create a proper keep-around loose ref
existingSha := "1e292f8fedd741b75372e19097c76d327140c312"
existingRefName := fmt.Sprintf("refs/keep-around/%s", existingSha)
@@ -456,8 +461,9 @@ func mustCreateFileWithTimes(t testing.TB, path string, mTime time.Time) {
func TestGarbageCollectDeltaIslands(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
gittest.TestDeltaIslands(t, cfg, repoPath, func() error {
_, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: repo})
diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go
index 7ebac9971..8f81ac0fb 100644
--- a/internal/gitaly/service/repository/info_attributes_test.go
+++ b/internal/gitaly/service/repository/info_attributes_test.go
@@ -15,7 +15,9 @@ import (
func TestGetInfoAttributesExisting(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
infoPath := filepath.Join(repoPath, "info")
require.NoError(t, os.MkdirAll(infoPath, 0o755))
@@ -27,9 +29,8 @@ func TestGetInfoAttributesExisting(t *testing.T) {
require.NoError(t, err)
request := &gitalypb.GetInfoAttributesRequest{Repository: repo}
- testCtx := testhelper.Context(t)
- stream, err := client.GetInfoAttributes(testCtx, request)
+ stream, err := client.GetInfoAttributes(ctx, request)
require.NoError(t, err)
receivedData, err := io.ReadAll(streamio.NewReader(func() ([]byte, error) {
@@ -43,12 +44,13 @@ func TestGetInfoAttributesExisting(t *testing.T) {
func TestGetInfoAttributesNonExisting(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
request := &gitalypb.GetInfoAttributesRequest{Repository: repo}
- testCtx := testhelper.Context(t)
- response, err := client.GetInfoAttributes(testCtx, request)
+ response, err := client.GetInfoAttributes(ctx, request)
require.NoError(t, err)
message, err := response.Recv()
diff --git a/internal/gitaly/service/repository/merge_base_test.go b/internal/gitaly/service/repository/merge_base_test.go
index d5afed222..a9559aa67 100644
--- a/internal/gitaly/service/repository/merge_base_test.go
+++ b/internal/gitaly/service/repository/merge_base_test.go
@@ -11,7 +11,9 @@ import (
func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
@@ -63,8 +65,6 @@ func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
request := &gitalypb.FindMergeBaseRequest{
Repository: repo,
Revisions: testCase.revisions,
@@ -80,8 +80,9 @@ func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) {
func TestFailedFindMergeBaseRequestDueToValidations(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
request := &gitalypb.FindMergeBaseRequest{
Repository: repo,
diff --git a/internal/gitaly/service/repository/midx_test.go b/internal/gitaly/service/repository/midx_test.go
index c6814df2f..269b2c6b5 100644
--- a/internal/gitaly/service/repository/midx_test.go
+++ b/internal/gitaly/service/repository/midx_test.go
@@ -26,8 +26,9 @@ import (
func TestMidxWrite(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
_, err := client.MidxRepack(ctx, &gitalypb.MidxRepackRequest{Repository: repo})
assert.NoError(t, err)
@@ -43,8 +44,9 @@ func TestMidxWrite(t *testing.T) {
func TestMidxRewrite(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
midxPath := filepath.Join(repoPath, MidxRelPath)
@@ -69,8 +71,9 @@ func TestMidxRewrite(t *testing.T) {
func TestMidxRepack(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
// add some pack files with different sizes
packsAdded := 5
@@ -111,7 +114,7 @@ func TestMidxRepack_transactional(t *testing.T) {
txManager := transaction.NewTrackingManager()
- cfg, repo, repoPath, client := setupRepositoryService(t, testserver.WithTransactionManager(txManager))
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t, testserver.WithTransactionManager(txManager))
// Reset the votes after creating the test repository.
txManager.Reset()
diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go
index 0d27d8c55..c35ffa924 100644
--- a/internal/gitaly/service/repository/optimize_test.go
+++ b/internal/gitaly/service/repository/optimize_test.go
@@ -40,11 +40,12 @@ func getNewestPackfileModtime(t *testing.T, repoPath string) time.Time {
func TestOptimizeRepository(t *testing.T) {
t.Parallel()
- cfg, repoProto, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repoProto, repoPath, client := setupRepositoryService(ctx, t)
gittest.Exec(t, cfg, "-C", repoPath, "repack", "-A", "-b")
gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--size-multiple=4", "--split=replace", "--reachable", "--changed-paths")
- ctx := testhelper.Context(t)
hasBitmap, err := stats.HasBitmap(repoPath)
require.NoError(t, err)
@@ -148,7 +149,9 @@ func TestOptimizeRepository(t *testing.T) {
func TestOptimizeRepositoryValidation(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
@@ -171,7 +174,6 @@ func TestOptimizeRepositoryValidation(t *testing.T) {
expectedErrorCode: codes.NotFound,
},
}
- ctx := testhelper.Context(t)
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
diff --git a/internal/gitaly/service/repository/raw_changes_test.go b/internal/gitaly/service/repository/raw_changes_test.go
index d480d4621..d1d7c21ff 100644
--- a/internal/gitaly/service/repository/raw_changes_test.go
+++ b/internal/gitaly/service/repository/raw_changes_test.go
@@ -16,7 +16,9 @@ import (
func TestGetRawChanges(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
oldRev string
@@ -91,8 +93,6 @@ func TestGetRawChanges(t *testing.T) {
for _, tc := range testCases {
t.Run(fmt.Sprintf("old:%s,new:%s", tc.oldRev, tc.newRev), func(t *testing.T) {
- ctx := testhelper.Context(t)
-
req := &gitalypb.GetRawChangesRequest{
Repository: repo,
FromRevision: tc.oldRev,
@@ -119,8 +119,8 @@ func TestGetRawChangesSpecialCharacters(t *testing.T) {
// This test looks for a specific path known to contain special
// characters.
- _, repo, _, client := setupRepositoryService(t)
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
req := &gitalypb.GetRawChangesRequest{
Repository: repo,
@@ -158,7 +158,9 @@ func collectChanges(t *testing.T, stream gitalypb.RepositoryService_GetRawChange
func TestGetRawChangesFailures(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
oldRev string
@@ -187,8 +189,6 @@ func TestGetRawChangesFailures(t *testing.T) {
for _, tc := range testCases {
t.Run(fmt.Sprintf("old:%s,new:%s", tc.oldRev, tc.newRev), func(t *testing.T) {
- ctx := testhelper.Context(t)
-
req := &gitalypb.GetRawChangesRequest{
Repository: repo,
FromRevision: tc.oldRev,
@@ -213,8 +213,9 @@ func TestGetRawChangesFailures(t *testing.T) {
func TestGetRawChangesManyFiles(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
initCommit := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
req := &gitalypb.GetRawChangesRequest{
@@ -233,8 +234,9 @@ func TestGetRawChangesManyFiles(t *testing.T) {
func TestGetRawChangesMappingOperations(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
req := &gitalypb.GetRawChangesRequest{
Repository: repo,
@@ -274,7 +276,9 @@ func TestGetRawChangesMappingOperations(t *testing.T) {
func TestGetRawChangesInvalidUTF8Paths(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
const (
// These are arbitrary blobs known to exist in the test repository
@@ -294,7 +298,6 @@ func TestGetRawChangesInvalidUTF8Paths(t *testing.T) {
OID: blobID2, Path: nonUTF8Filename, Mode: "100644",
}),
)
- ctx := testhelper.Context(t)
req := &gitalypb.GetRawChangesRequest{
Repository: repo,
diff --git a/internal/gitaly/service/repository/remove_test.go b/internal/gitaly/service/repository/remove_test.go
index 39cb6aba2..962b6e0b8 100644
--- a/internal/gitaly/service/repository/remove_test.go
+++ b/internal/gitaly/service/repository/remove_test.go
@@ -55,7 +55,7 @@ func TestRemoveRepository_locking(t *testing.T) {
ctx := testhelper.Context(t)
// Praefect special-cases repository removals, so we disable Praefect here.
- _, repo, repoPath, client := setupRepositoryService(t, testserver.WithDisablePraefect())
+ _, repo, repoPath, client := setupRepositoryService(ctx, t, testserver.WithDisablePraefect())
// Simulate a concurrent RPC holding the repository lock.
lockPath := repoPath + ".lock"
diff --git a/internal/gitaly/service/repository/rename_test.go b/internal/gitaly/service/repository/rename_test.go
index 747af33fd..c3528cf1d 100644
--- a/internal/gitaly/service/repository/rename_test.go
+++ b/internal/gitaly/service/repository/rename_test.go
@@ -20,7 +20,7 @@ func TestRenameRepository_success(t *testing.T) {
ctx := testhelper.Context(t)
// Praefect does not move repositories on the disk so this test case is not run with Praefect.
- cfg, repo, _, client := setupRepositoryService(t, testserver.WithDisablePraefect())
+ cfg, repo, _, client := setupRepositoryService(ctx, t, testserver.WithDisablePraefect())
const targetPath = "a-new-location"
_, err := client.RenameRepository(ctx, &gitalypb.RenameRepositoryRequest{
@@ -73,7 +73,7 @@ func TestRenameRepository_invalidRequest(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go
index afd630c8b..8a9c4bd3a 100644
--- a/internal/gitaly/service/repository/repack_test.go
+++ b/internal/gitaly/service/repository/repack_test.go
@@ -19,7 +19,9 @@ import (
func TestRepackIncrementalSuccess(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
+ ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
packPath := filepath.Join(repoPath, "objects", "pack")
@@ -28,7 +30,6 @@ func TestRepackIncrementalSuccess(t *testing.T) {
// Stamp taken from https://golang.org/pkg/time/#pkg-constants
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, filepath.Join(packPath, "*"))
testTime := time.Date(2006, 0o1, 0o2, 15, 0o4, 0o5, 0, time.UTC)
- ctx := testhelper.Context(t)
c, err := client.RepackIncremental(ctx, &gitalypb.RepackIncrementalRequest{Repository: repo})
assert.NoError(t, err)
assert.NotNil(t, c)
@@ -47,7 +48,7 @@ func TestRepackIncrementalCollectLogStatistics(t *testing.T) {
ctx := testhelper.Context(t)
logger, hook := test.NewNullLogger()
- _, repo, _, client := setupRepositoryService(t, testserver.WithLogger(logger))
+ _, repo, _, client := setupRepositoryService(ctx, t, testserver.WithLogger(logger))
_, err := client.RepackIncremental(ctx, &gitalypb.RepackIncrementalRequest{Repository: repo})
assert.NoError(t, err)
@@ -58,7 +59,8 @@ func TestRepackIncrementalCollectLogStatistics(t *testing.T) {
func TestRepackLocal(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
altObjectsDir := "./alt-objects"
alternateCommit := gittest.WriteCommit(t, cfg, repoPath,
@@ -71,7 +73,6 @@ func TestRepackLocal(t *testing.T) {
gittest.WithMessage("main commit"),
gittest.WithBranch("main-odb"),
)
- ctx := testhelper.Context(t)
// Set GIT_ALTERNATE_OBJECT_DIRECTORIES on the outgoing request. The
// intended use case of the behavior we're testing here is that
@@ -175,7 +176,7 @@ func TestRepackFullCollectLogStatistics(t *testing.T) {
ctx := testhelper.Context(t)
logger, hook := test.NewNullLogger()
- _, repo, _, client := setupRepositoryService(t, testserver.WithLogger(logger))
+ _, repo, _, client := setupRepositoryService(ctx, t, testserver.WithLogger(logger))
_, err := client.RepackFull(ctx, &gitalypb.RepackFullRequest{Repository: repo})
require.NoError(t, err)
@@ -236,8 +237,9 @@ func TestRepackFullFailure(t *testing.T) {
func TestRepackFullDeltaIslands(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
gittest.TestDeltaIslands(t, cfg, repoPath, func() error {
_, err := client.RepackFull(ctx, &gitalypb.RepackFullRequest{Repository: repo})
diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go
index f1150f602..a5cd0d85b 100644
--- a/internal/gitaly/service/repository/repository_test.go
+++ b/internal/gitaly/service/repository/repository_test.go
@@ -111,9 +111,10 @@ func TestRepositoryExists(t *testing.T) {
func TestSuccessfulHasLocalBranches(t *testing.T) {
t.Parallel()
- cfg, repo, _, client := setupRepositoryService(t)
ctx := testhelper.Context(t)
+ cfg, repo, _, client := setupRepositoryService(ctx, t)
+
emptyRepo, _ := gittest.CreateRepository(ctx, t, cfg)
testCases := []struct {
diff --git a/internal/gitaly/service/repository/restore_custom_hooks_test.go b/internal/gitaly/service/repository/restore_custom_hooks_test.go
index 0b1c716b9..294b51c45 100644
--- a/internal/gitaly/service/repository/restore_custom_hooks_test.go
+++ b/internal/gitaly/service/repository/restore_custom_hooks_test.go
@@ -15,8 +15,9 @@ import (
func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, repoPath, client := setupRepositoryService(ctx, t)
stream, err := client.RestoreCustomHooks(ctx)
require.NoError(t, err)
@@ -60,8 +61,9 @@ func TestFailedRestoreCustomHooksDueToValidations(t *testing.T) {
func TestFailedRestoreCustomHooksDueToBadTar(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
+
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
stream, err := client.RestoreCustomHooks(ctx)
diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go
index c2951d6a8..777c8d0c1 100644
--- a/internal/gitaly/service/repository/search_files_test.go
+++ b/internal/gitaly/service/repository/search_files_test.go
@@ -88,7 +88,7 @@ func TestSearchFilesByContentSuccessful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
@@ -153,7 +153,7 @@ func TestSearchFilesByContentLargeFile(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRepositoryServiceWithWorktree(t)
+ cfg, repo, repoPath, client := setupRepositoryServiceWithWorktree(ctx, t)
committerName := "Scrooge McDuck"
committerEmail := "scrooge@mcduck.com"
@@ -283,7 +283,7 @@ func TestSearchFilesByNameSuccessful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- _, repo, _, client := setupRepositoryService(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
diff --git a/internal/gitaly/service/repository/size_test.go b/internal/gitaly/service/repository/size_test.go
index c55134d91..ecb7754f6 100644
--- a/internal/gitaly/service/repository/size_test.go
+++ b/internal/gitaly/service/repository/size_test.go
@@ -19,10 +19,11 @@ const testRepoMinSizeKB = 10000
func TestSuccessfulRepositorySizeRequest(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
- request := &gitalypb.RepositorySizeRequest{Repository: repo}
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
+
+ request := &gitalypb.RepositorySizeRequest{Repository: repo}
response, err := client.RepositorySize(ctx, request)
require.NoError(t, err)
@@ -60,9 +61,10 @@ func TestFailedRepositorySizeRequest(t *testing.T) {
func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) {
t.Parallel()
- _, repo, _, client := setupRepositoryService(t)
- repo.GitObjectDirectory = "objects/"
+
ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
+ repo.GitObjectDirectory = "objects/"
request := &gitalypb.GetObjectDirectorySizeRequest{Repository: repo}
response, err := client.GetObjectDirectorySize(ctx, request)
diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go
index 7a531dd9f..3e89eeb5a 100644
--- a/internal/gitaly/service/repository/snapshot_test.go
+++ b/internal/gitaly/service/repository/snapshot_test.go
@@ -47,7 +47,7 @@ func touch(t *testing.T, format string, args ...interface{}) {
func TestGetSnapshotSuccess(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ cfg, repo, repoPath, client := setupRepositoryService(testhelper.Context(t), t)
// Ensure certain files exist in the test repo.
// WriteCommit produces a loose object with the given sha
@@ -110,7 +110,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- cfg, repoProto, repoPath, client := setupRepositoryService(t)
+ cfg, repoProto, repoPath, client := setupRepositoryService(ctx, t)
alternateObjDir := tc.alternatePathFunc(t, cfg.Storages[0].Path, filepath.Join(repoPath, "objects"))
absoluteAlternateObjDir := alternateObjDir
@@ -161,7 +161,7 @@ func TestGetSnapshot_alternateObjectDirectory(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
locator := config.NewLocator(cfg)
alternatesFile, err := locator.InfoAlternatesPath(repo)
@@ -282,7 +282,7 @@ func TestGetSnapshotFailsIfRepositoryMissing(t *testing.T) {
func TestGetSnapshotFailsIfRepositoryContainsSymlink(t *testing.T) {
t.Parallel()
- _, repo, repoPath, client := setupRepositoryService(t)
+ _, repo, repoPath, client := setupRepositoryService(testhelper.Context(t), t)
// Make packed-refs into a symlink to break GetSnapshot()
packedRefsFile := filepath.Join(repoPath, "packed-refs")
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 300f11de3..e50ec6eb6 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -164,10 +164,10 @@ func runRepositoryService(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Serv
return client, serverSocketPath
}
-func setupRepositoryService(t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {
+func setupRepositoryService(ctx context.Context, t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {
cfg, client := setupRepositoryServiceWithoutRepo(t, opts...)
- repo, repoPath := gittest.CreateRepository(context.TODO(), t, cfg, gittest.CreateRepositoryConfig{
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
Seed: gittest.SeedGitLabTest,
})
return cfg, repo, repoPath, client
@@ -185,8 +185,8 @@ func setupRepositoryServiceWithoutRepo(t testing.TB, opts ...testserver.GitalySe
return cfg, client
}
-func setupRepositoryServiceWithWorktree(t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {
- cfg, repo, repoPath, client := setupRepositoryService(t, opts...)
+func setupRepositoryServiceWithWorktree(ctx context.Context, t testing.TB, opts ...testserver.GitalyServerOpt) (config.Cfg, *gitalypb.Repository, string, gitalypb.RepositoryServiceClient) {
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t, opts...)
gittest.AddWorktree(t, cfg, repoPath, "worktree")
repoPath = filepath.Join(repoPath, "worktree")
diff --git a/internal/gitaly/service/repository/write_ref_test.go b/internal/gitaly/service/repository/write_ref_test.go
index 65dc2e390..e2070e54f 100644
--- a/internal/gitaly/service/repository/write_ref_test.go
+++ b/internal/gitaly/service/repository/write_ref_test.go
@@ -13,7 +13,8 @@ import (
)
func TestWriteRefSuccessful(t *testing.T) {
- cfg, repo, repoPath, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ cfg, repo, repoPath, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
@@ -48,9 +49,7 @@ func TestWriteRefSuccessful(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
_, err := client.WriteRef(ctx, tc.req)
-
require.NoError(t, err)
if bytes.Equal(tc.req.Ref, []byte("HEAD")) {
@@ -71,7 +70,8 @@ func TestWriteRefSuccessful(t *testing.T) {
}
func TestWriteRefValidationError(t *testing.T) {
- _, repo, _, client := setupRepositoryService(t)
+ ctx := testhelper.Context(t)
+ _, repo, _, client := setupRepositoryService(ctx, t)
testCases := []struct {
desc string
@@ -135,7 +135,6 @@ func TestWriteRefValidationError(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
_, err := client.WriteRef(ctx, tc.req)
testhelper.RequireGrpcCode(t, err, codes.InvalidArgument)