diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-10-19 13:23:30 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-10-19 13:33:51 +0300 |
commit | 64ee64a4d30f6076aad214dc4ddb28cd18b1d59c (patch) | |
tree | 5d6f7be1fd645c5f5502039c75c4db33a1882564 | |
parent | 8c09007d6a340364eda51476ab99a3d27c720713 (diff) |
Fix broken test performing concurrent writes to shared repo
TestUserRebaseToRef_failure is sharing a test repository between the
subtests. The subtests are ran concurrently. Each of the subtests are
resetting the valid target ref on beginning. As the tests are ran
concurrently, they're all modifying the repository concurrently. This
won't work anymore with transactions enabled and will cause flakes.
As none of the tests should modify the repository, stop resetting the
target ref at the beginning of each test. If one of the tests fails and
modifies the ref, the other subtests could fail as well. This can be
improved later by actually setting up independent test state for each
of the tests. For now, fix the flake.
-rw-r--r-- | internal/gitaly/service/operations/rebase_to_ref_test.go | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/internal/gitaly/service/operations/rebase_to_ref_test.go b/internal/gitaly/service/operations/rebase_to_ref_test.go index e178b595a..559ca5fcd 100644 --- a/internal/gitaly/service/operations/rebase_to_ref_test.go +++ b/internal/gitaly/service/operations/rebase_to_ref_test.go @@ -96,8 +96,8 @@ func testUserRebaseToRefFailure(t *testing.T, ctx context.Context) { mergeBaseOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("first commit")) - validTargetRef := []byte("refs/merge-requests/x/merge") - validTargetRefOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("commit to target ref")) + validTargetRef := "refs/merge-requests/x/merge" + gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("commit to target ref"), gittest.WithReference(validTargetRef)) validSourceOID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("commit source SHA"), gittest.WithParents(mergeBaseOID)) validSourceSha := validSourceOID.String() validFirstParentRef := []byte("refs/heads/main") @@ -107,7 +107,7 @@ func testUserRebaseToRefFailure(t *testing.T, ctx context.Context) { desc string repo *gitalypb.Repository user *gitalypb.User - targetRef []byte + targetRef string sourceSha string firstParentRef []byte expectedOldOID string @@ -158,7 +158,7 @@ func testUserRebaseToRefFailure(t *testing.T, ctx context.Context) { desc: "invalid target ref", repo: repo, user: gittest.TestUser, - targetRef: []byte("refs/heads/branch"), + targetRef: "refs/heads/branch", sourceSha: validSourceSha, firstParentRef: validFirstParentRef, expectedError: structerr.NewInvalidArgument("%w", errors.New("invalid TargetRef")), @@ -186,7 +186,7 @@ func testUserRebaseToRefFailure(t *testing.T, ctx context.Context) { desc: "ambiguous target reference", repo: repo, user: gittest.TestUser, - targetRef: []byte("refs/merge-requests/x/m*"), + targetRef: "refs/merge-requests/x/m*", sourceSha: validSourceSha, firstParentRef: validFirstParentRef, expectedError: structerr.NewInvalidArgument(`target reference is ambiguous: reference is ambiguous: conflicts with "refs/merge-requests/x/merge"`), @@ -195,16 +195,13 @@ func testUserRebaseToRefFailure(t *testing.T, ctx context.Context) { for _, tc := range testCases { tc := tc - t.Run(tc.desc, func(t *testing.T) { t.Parallel() - // reset target ref between tests - gittest.WriteRef(t, cfg, repoPath, git.ReferenceName(validTargetRef), validTargetRefOID) request := &gitalypb.UserRebaseToRefRequest{ Repository: tc.repo, User: tc.user, - TargetRef: tc.targetRef, + TargetRef: []byte(tc.targetRef), SourceSha: tc.sourceSha, FirstParentRef: tc.firstParentRef, ExpectedOldOid: tc.expectedOldOID, |