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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-12-13 21:15:04 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-12-15 09:49:26 +0300
commit2bf28a8f16fc5eea123fc056f34f544bfe880cd3 (patch)
tree5eec97ee24759058bc3176abfe361219a7bd4b87
parent799301b082d6c652a601e7c1aa8b0358b30bfe6a (diff)
ref: Refactor test that writes thousands of references
One of the tests for the `FindAllBranchNames()` RPC exercises what happens when we return thousands of references. To do so it creates a git-update-ref(1) instance and queues up all updates to it. While this is as efficient as it gets while using Git, it still is comparatively expensive to do it this way as it requires locking and whatnot. Refactor the test to just manually write out a `packed-refs` file.
-rw-r--r--internal/gitaly/service/ref/refs_test.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go
index f836da63f..5bd97483f 100644
--- a/internal/gitaly/service/ref/refs_test.go
+++ b/internal/gitaly/service/ref/refs_test.go
@@ -7,6 +7,8 @@ import (
"bytes"
"fmt"
"io"
+ "os"
+ "path/filepath"
"strings"
"testing"
@@ -14,7 +16,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
- "gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -61,12 +62,10 @@ func TestSuccessfulFindAllBranchNames(t *testing.T) {
//nolint:staticcheck
func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repoProto, _, client := setupRefService(t, ctx)
+ cfg, client := setupRefServiceWithoutRepo(t)
- repo := localrepo.NewTestRepo(t, cfg, repoProto)
- updater, err := updateref.New(ctx, repo)
- require.NoError(t, err)
- defer testhelper.MustClose(t, updater)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
// We want to create enough refs to overflow the default bufio.Scanner
// buffer. Such an overflow will cause scanner.Bytes() to become invalid
@@ -76,25 +75,26 @@ func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
refSizeLowerBound := 100
numRefs := 2 * bufio.MaxScanTokenSize / refSizeLowerBound
- require.NoError(t, updater.Start())
+ // Instead of using git-update-ref(1) to create the thousands of references we just write
+ // our own packed-refs file, which is significantly faster.
+ packedRefs, err := os.Create(filepath.Join(repoPath, "packed-refs"))
+ require.NoError(t, err)
- var testRefs []string
+ var expectedRefs [][]byte
for i := 0; i < numRefs; i++ {
refName := fmt.Sprintf("refs/heads/test-%0100d", i)
- require.True(t, len(refName) > refSizeLowerBound, "ref %q must be larger than %d", refName, refSizeLowerBound)
-
- require.NoError(t, updater.Create(git.ReferenceName(refName), "HEAD"))
- testRefs = append(testRefs, refName)
+ _, err := packedRefs.WriteString(fmt.Sprintf("%s %s\n", commitID, refName))
+ require.NoError(t, err)
+ expectedRefs = append(expectedRefs, []byte(refName))
}
+ testhelper.MustClose(t, packedRefs)
- require.NoError(t, updater.Commit())
-
- rpcRequest := &gitalypb.FindAllBranchNamesRequest{Repository: repoProto}
-
- c, err := client.FindAllBranchNames(ctx, rpcRequest)
+ c, err := client.FindAllBranchNames(ctx, &gitalypb.FindAllBranchNamesRequest{
+ Repository: repoProto,
+ })
require.NoError(t, err)
- var names [][]byte
+ var actualRefs [][]byte
for {
r, err := c.Recv()
if err == io.EOF {
@@ -102,12 +102,9 @@ func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
}
require.NoError(t, err)
- names = append(names, r.GetNames()...)
- }
-
- for _, branch := range testRefs {
- require.Contains(t, names, []byte(branch), "branch missing from response: %q", branch)
+ actualRefs = append(actualRefs, r.GetNames()...)
}
+ require.Equal(t, expectedRefs, actualRefs)
}
//nolint:staticcheck