diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-13 14:27:46 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-14 09:24:56 +0300 |
commit | b0b1299ef3a6b4e2e9738e3006f6576bfd43faf3 (patch) | |
tree | 2f20ebccddfb1434f39ad1d797df66893673e8fd | |
parent | 5958cf6357310f932b49915458ce8b9b592f7e9d (diff) |
server: Fix test race caused by concurrent UserCreateTag requests
The `TestAuthBeforeLimit()` functions verifies that the authentication
token's validity is checked before actually executing the RPC logic
itself. This is done by setting up a pre-receive hook that waits for the
tokens' validity duration such that the RPC is guaranteed to take longer
than the token would be valid.
The RPC call that is being executed is `UserCreateTag`, where we try to
create the same tag twice. While we would typically just force-overwrite
the tag and thus don't care about this race, the fact that we're waiting
in the pre-receive hook where refs would still be locked means that both
processes will try to lock the same ref concurrently. We haven't cared
about this in the past given that the updateref package never had
correct locking semantics. But now that we're fixing it to do proper
locking, it will cause the test to fail.
Fix this bug by simply creating two separate tags. We don't care about
the results of the RPC, but only about the artificial delay via the
hook. So changing what is being created is perfectly fine.
-rw-r--r-- | internal/gitaly/server/auth_test.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/internal/gitaly/server/auth_test.go b/internal/gitaly/server/auth_test.go index 027436ab4..94f5e9ef5 100644 --- a/internal/gitaly/server/auth_test.go +++ b/internal/gitaly/server/auth_test.go @@ -328,17 +328,6 @@ func TestAuthBeforeLimit(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - targetRevision := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd" - inputTagName := "to-be-créated-soon" - - request := &gitalypb.UserCreateTagRequest{ - Repository: repo, - TagName: []byte(inputTagName), - TargetRevision: []byte(targetRevision), - User: gittest.TestUser, - Message: []byte("a new tag!"), - } - defer func(d time.Duration) { gitalyauth.SetTokenValidityDuration(d) }(gitalyauth.TokenValidityDuration()) @@ -351,8 +340,15 @@ sleep %vs errChan := make(chan error) for i := 0; i < 2; i++ { + i := i go func() { - _, err := client.UserCreateTag(ctx, request) + _, err := client.UserCreateTag(ctx, &gitalypb.UserCreateTagRequest{ + Repository: repo, + TagName: []byte(fmt.Sprintf("tag-name-%d", i)), + TargetRevision: []byte("c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"), + User: gittest.TestUser, + Message: []byte("a new tag!"), + }) errChan <- err }() } |