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>2023-10-19 21:51:09 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2023-10-19 21:53:22 +0300
commit0ecd6f99c12949e45cc425dd76d38fe05dfe9c8d (patch)
tree8ad610357444a48941bc3e28c3f70d6e0696b653
parentc7c7764c3d542ae23943d119294718ba1e905cab (diff)
Fix TestUserCreateBranch_successful writing into shared repository
TestUserCreateBranch_successful is setting up a shared repository in the tests. It then proceeds to concurrently write to the shared repository in the subtests. This leads to indeterministic results as the branch may or may not be already created by one of the other subtests. Fix this by running each of the tests agains their own repository. As all tests are now running agains their own repositories, we know longer need to delete the created branch at the end of the test.
-rw-r--r--internal/gitaly/service/operations/user_create_branch_test.go89
1 files changed, 52 insertions, 37 deletions
diff --git a/internal/gitaly/service/operations/user_create_branch_test.go b/internal/gitaly/service/operations/user_create_branch_test.go
index 964ab5239..11c3f4926 100644
--- a/internal/gitaly/service/operations/user_create_branch_test.go
+++ b/internal/gitaly/service/operations/user_create_branch_test.go
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service"
@@ -28,29 +29,27 @@ func TestUserCreateBranch_successful(t *testing.T) {
ctx := testhelper.Context(t)
ctx, cfg, client := setupOperationsService(t, ctx)
- repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
-
- startPoint := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(
- gittest.TreeEntry{Mode: "100644", Path: "foo", Content: "bar"},
- ))
-
- localRepo := localrepo.NewTestRepo(t, cfg, repo)
- startPointCommit, err := localRepo.ReadCommit(ctx, startPoint.Revision())
- require.NoError(t, err)
-
- testCases := []struct {
- desc string
+ type setupData struct {
branchName string
startPoint string
expectedBranch *gitalypb.Branch
+ }
+
+ testCases := []struct {
+ desc string
+ setup func(git.ObjectID, *gitalypb.GitCommit) setupData
}{
{
- desc: "valid branch",
- branchName: "new-branch",
- startPoint: startPoint.String(),
- expectedBranch: &gitalypb.Branch{
- Name: []byte("new-branch"),
- TargetCommit: startPointCommit,
+ desc: "valid branch",
+ setup: func(startPoint git.ObjectID, startPointCommit *gitalypb.GitCommit) setupData {
+ return setupData{
+ branchName: "new-branch",
+ startPoint: startPoint.String(),
+ expectedBranch: &gitalypb.Branch{
+ Name: []byte("new-branch"),
+ TargetCommit: startPointCommit,
+ },
+ }
},
},
// On input like heads/foo and refs/heads/foo we don't
@@ -59,21 +58,29 @@ func TestUserCreateBranch_successful(t *testing.T) {
// prepend refs/heads/*, so you get
// refs/heads/heads/foo and refs/heads/refs/heads/foo
{
- desc: "valid branch",
- branchName: "heads/new-branch",
- startPoint: startPoint.String(),
- expectedBranch: &gitalypb.Branch{
- Name: []byte("heads/new-branch"),
- TargetCommit: startPointCommit,
+ desc: "valid branch",
+ setup: func(startPoint git.ObjectID, startPointCommit *gitalypb.GitCommit) setupData {
+ return setupData{
+ branchName: "heads/new-branch",
+ startPoint: startPoint.String(),
+ expectedBranch: &gitalypb.Branch{
+ Name: []byte("heads/new-branch"),
+ TargetCommit: startPointCommit,
+ },
+ }
},
},
{
- desc: "valid branch",
- branchName: "refs/heads/new-branch",
- startPoint: startPoint.String(),
- expectedBranch: &gitalypb.Branch{
- Name: []byte("refs/heads/new-branch"),
- TargetCommit: startPointCommit,
+ desc: "valid branch",
+ setup: func(startPoint git.ObjectID, startPointCommit *gitalypb.GitCommit) setupData {
+ return setupData{
+ branchName: "refs/heads/new-branch",
+ startPoint: startPoint.String(),
+ expectedBranch: &gitalypb.Branch{
+ Name: []byte("refs/heads/new-branch"),
+ TargetCommit: startPointCommit,
+ },
+ }
},
},
}
@@ -84,21 +91,29 @@ func TestUserCreateBranch_successful(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
- branchName := tc.branchName
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
+
+ startPoint := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "foo", Content: "bar"},
+ ))
+
+ localRepo := localrepo.NewTestRepo(t, cfg, repo)
+ startPointCommit, err := localRepo.ReadCommit(ctx, startPoint.Revision())
+ require.NoError(t, err)
+
+ setup := tc.setup(startPoint, startPointCommit)
+
+ branchName := setup.branchName
request := &gitalypb.UserCreateBranchRequest{
Repository: repo,
BranchName: []byte(branchName),
- StartPoint: []byte(tc.startPoint),
+ StartPoint: []byte(setup.startPoint),
User: gittest.TestUser,
}
response, err := client.UserCreateBranch(ctx, request)
- if tc.expectedBranch != nil {
- defer gittest.Exec(t, cfg, "-C", repoPath, "branch", "-D", branchName)
- }
-
require.NoError(t, err)
- require.Equal(t, tc.expectedBranch, response.Branch)
+ require.Equal(t, setup.expectedBranch, response.Branch)
branches := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchName)
require.Contains(t, string(branches), "refs/heads/"+branchName)