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:
authorPavlo Strokov <pstrokov@gitlab.com>2021-03-15 15:10:38 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-03-18 12:49:31 +0300
commit63c55949d54543fce205c0f750f8fc502ed9566a (patch)
treea26b220fde2aea0495789d584b35432bc6212751
parent2093a05fa4214e69abc75eacea26e926266264b1 (diff)
Linguist converted into an instantiation dependency
Implementation of the linguist package relies on the package-private state: the use of the colorMap variable. It is filled with a hook mechanism after validation of the gitaly configuration. The problem is that this operation invokes ruby code to get it done and this call is pretty expensive. It also doesn't allow us to convert tests to parallel as it causes race conditions in attempt to fill the global variable. The solution to this problem is creation of the struct instance that encapsulates the state and can be instantiated only when needed. The change also includes minification in generating test configuration that does not require to make a ruby call and uses a stub file for initialisation. The behaviour could be returned back to the normal with usage of the WithActualLinguist option for configuration creation. The change also includes renames of the test functions for the linguist package. The change speeds up execution of the tests: before 0m43.907s and after 0m21.659s on my local. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r--cmd/gitaly-ssh/auth_test.go2
-rw-r--r--cmd/gitaly/main.go8
-rw-r--r--internal/gitaly/linguist/linguist.go47
-rw-r--r--internal/gitaly/linguist/linguist_test.go30
-rw-r--r--internal/gitaly/server/auth_test.go2
-rw-r--r--internal/gitaly/service/commit/languages.go5
-rw-r--r--internal/gitaly/service/commit/languages_test.go7
-rw-r--r--internal/gitaly/service/commit/server.go6
-rw-r--r--internal/gitaly/service/commit/testhelper_test.go12
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go2
-rw-r--r--internal/gitaly/service/register.go4
-rw-r--r--internal/gitaly/service/repository/fetch_test.go2
-rw-r--r--internal/praefect/server_factory_test.go6
-rw-r--r--internal/testhelper/testcfg/gitaly_builder.go19
-rw-r--r--internal/testhelper/testserver/gitaly.go5
15 files changed, 106 insertions, 51 deletions
diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go
index 50160eb0c..bc428ef04 100644
--- a/cmd/gitaly-ssh/auth_test.go
+++ b/cmd/gitaly-ssh/auth_test.go
@@ -136,7 +136,7 @@ func runServer(t *testing.T, secure bool, cfg config.Cfg, connectionType string,
gitCmdFactory := git.NewExecCommandFactory(cfg)
srv, err := server.New(secure, cfg, testhelper.DiscardTestEntry(t))
require.NoError(t, err)
- service.RegisterAll(srv, cfg, nil, hookManager, txManager, locator, conns, gitCmdFactory)
+ service.RegisterAll(srv, cfg, nil, hookManager, txManager, locator, conns, gitCmdFactory, nil)
listener, err := net.Listen(connectionType, addr)
require.NoError(t, err)
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go
index 278f48fb5..ac988ef6f 100644
--- a/cmd/gitaly/main.go
+++ b/cmd/gitaly/main.go
@@ -17,6 +17,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config/sentry"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/server"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service"
@@ -167,6 +168,11 @@ func run(cfg config.Cfg) error {
gitalyServerFactory := server.NewGitalyServerFactory(cfg)
defer gitalyServerFactory.Stop()
+ ling, err := linguist.New(cfg)
+ if err != nil {
+ return fmt.Errorf("linguist instance creation: %w", err)
+ }
+
b.StopAction = gitalyServerFactory.GracefulStop
rubySrv := rubyserver.New(cfg)
@@ -189,7 +195,7 @@ func run(cfg config.Cfg) error {
if err != nil {
return fmt.Errorf("create gRPC server: %w", err)
}
- service.RegisterAll(srv, cfg, rubySrv, hookManager, transactionManager, locator, conns, gitCmdFactory)
+ service.RegisterAll(srv, cfg, rubySrv, hookManager, transactionManager, locator, conns, gitCmdFactory, ling)
b.RegisterStarter(starter.New(c, srv))
}
diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go
index 9356a8af1..8cb187569 100644
--- a/internal/gitaly/linguist/linguist.go
+++ b/internal/gitaly/linguist/linguist.go
@@ -15,13 +15,8 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
)
-func init() {
- config.RegisterHook(LoadColors)
-}
-
var (
exportedEnvVars = []string{"HOME", "PATH", "GEM_HOME", "BUNDLE_PATH", "BUNDLE_APP_CONFIG"}
- colorMap = make(map[string]Language)
)
// Language is used to parse Linguist's language.json file.
@@ -32,8 +27,31 @@ type Language struct {
// ByteCountPerLanguage represents a counter value (bytes) per language.
type ByteCountPerLanguage map[string]uint64
+// Instance is a holder of the defined in the system language settings.
+type Instance struct {
+ colorMap map[string]Language
+}
+
+// New loads the name->color map from the Linguist gem and returns initialised instance
+// to use back to the caller or an error.
+func New(cfg config.Cfg) (*Instance, error) {
+ jsonReader, err := openLanguagesJSON(cfg)
+ if err != nil {
+ return nil, err
+ }
+ defer jsonReader.Close()
+
+ var inst Instance
+
+ if err := json.NewDecoder(jsonReader).Decode(&inst.colorMap); err != nil {
+ return nil, err
+ }
+
+ return &inst, nil
+}
+
// Stats returns the repository's language stats as reported by 'git-linguist'.
-func Stats(ctx context.Context, cfg config.Cfg, repoPath string, commitID string) (ByteCountPerLanguage, error) {
+func (inst *Instance) Stats(ctx context.Context, cfg config.Cfg, repoPath string, commitID string) (ByteCountPerLanguage, error) {
cmd, err := startGitLinguist(ctx, cfg, repoPath, commitID, "stats")
if err != nil {
return nil, err
@@ -53,8 +71,8 @@ func Stats(ctx context.Context, cfg config.Cfg, repoPath string, commitID string
}
// Color returns the color Linguist has assigned to language.
-func Color(language string) string {
- if color := colorMap[language].Color; color != "" {
+func (inst *Instance) Color(language string) string {
+ if color := inst.colorMap[language].Color; color != "" {
return color
}
@@ -62,17 +80,6 @@ func Color(language string) string {
return fmt.Sprintf("#%x", colorSha[0:3])
}
-// LoadColors loads the name->color map from the Linguist gem.
-func LoadColors(cfg *config.Cfg) error {
- jsonReader, err := openLanguagesJSON(cfg)
- if err != nil {
- return err
- }
- defer jsonReader.Close()
-
- return json.NewDecoder(jsonReader).Decode(&colorMap)
-}
-
func startGitLinguist(ctx context.Context, cfg config.Cfg, repoPath string, commitID string, linguistCommand string) (*command.Command, error) {
bundle, err := exec.LookPath("bundle")
if err != nil {
@@ -115,7 +122,7 @@ func startGitLinguist(ctx context.Context, cfg config.Cfg, repoPath string, comm
return internalCmd, nil
}
-func openLanguagesJSON(cfg *config.Cfg) (io.ReadCloser, error) {
+func openLanguagesJSON(cfg config.Cfg) (io.ReadCloser, error) {
if jsonPath := cfg.Ruby.LinguistLanguagesPath; jsonPath != "" {
// This is a fallback for environments where dynamic discovery of the
// linguist path via Bundler is not working for some reason, for example
diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go
index 58f10e81a..6188204d0 100644
--- a/internal/gitaly/linguist/linguist_test.go
+++ b/internal/gitaly/linguist/linguist_test.go
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
)
@@ -22,40 +23,41 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func TestStatsUnmarshalJSONError(t *testing.T) {
+func TestInstance_Stats_unmarshalJSONError(t *testing.T) {
cfg := testcfg.Build(t)
ctx, cancel := testhelper.Context()
defer cancel()
+ ling, err := New(cfg)
+ require.NoError(t, err)
+
// When an error occurs, this used to trigger JSON marshelling of a plain string
// the new behaviour shouldn't do that, and return an command error
- _, err := Stats(ctx, cfg, "/var/empty", "deadbeef")
+ _, err = ling.Stats(ctx, cfg, "/var/empty", "deadbeef")
require.Error(t, err)
_, ok := err.(*json.SyntaxError)
require.False(t, ok, "expected the error not be a json Syntax Error")
}
-func TestLoadLanguages(t *testing.T) {
- cfg := testcfg.Build(t)
+func TestNew(t *testing.T) {
+ cfg := testcfg.Build(t, testcfg.WithRealLinguist())
- colorMap = make(map[string]Language)
- require.NoError(t, LoadColors(&cfg), "load colors")
+ ling, err := New(cfg)
+ require.NoError(t, err)
- require.Equal(t, "#701516", Color("Ruby"), "color value for 'Ruby'")
+ require.Equal(t, "#701516", ling.Color("Ruby"), "color value for 'Ruby'")
}
-func TestLoadLanguagesCustomPath(t *testing.T) {
- cfg := testcfg.Build(t)
-
+func TestNew_loadLanguagesCustomPath(t *testing.T) {
jsonPath, err := filepath.Abs("testdata/fake-languages.json")
require.NoError(t, err)
- cfg.Ruby.LinguistLanguagesPath = jsonPath
+ cfg := testcfg.Build(t, testcfg.WithBase(config.Cfg{Ruby: config.Ruby{LinguistLanguagesPath: jsonPath}}))
- colorMap = make(map[string]Language)
- require.NoError(t, LoadColors(&cfg), "load colors")
+ ling, err := New(cfg)
+ require.NoError(t, err)
- require.Equal(t, "foo color", Color("FooBar"))
+ require.Equal(t, "foo color", ling.Color("FooBar"))
}
diff --git a/internal/gitaly/server/auth_test.go b/internal/gitaly/server/auth_test.go
index c1a91a93a..c38a33375 100644
--- a/internal/gitaly/server/auth_test.go
+++ b/internal/gitaly/server/auth_test.go
@@ -221,7 +221,7 @@ func runServer(t *testing.T, cfg config.Cfg) (string, func()) {
srv, err := New(false, cfg, testhelper.DiscardTestEntry(t))
require.NoError(t, err)
- service.RegisterAll(srv, cfg, rubyServer, hookManager, txManager, locator, conns, gitCmdFactory)
+ service.RegisterAll(srv, cfg, rubyServer, hookManager, txManager, locator, conns, gitCmdFactory, nil)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName(t)
listener, err := net.Listen("unix", serverSocketPath)
diff --git a/internal/gitaly/service/commit/languages.go b/internal/gitaly/service/commit/languages.go
index 894b5d118..4fd4cb164 100644
--- a/internal/gitaly/service/commit/languages.go
+++ b/internal/gitaly/service/commit/languages.go
@@ -10,7 +10,6 @@ import (
"strings"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
@@ -46,7 +45,7 @@ func (s *server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLangua
if err != nil {
return nil, err
}
- stats, err := linguist.Stats(ctx, s.cfg, repoPath, commitID)
+ stats, err := s.linguist.Stats(ctx, s.cfg, repoPath, commitID)
if err != nil {
return nil, err
}
@@ -69,7 +68,7 @@ func (s *server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLangua
l := &gitalypb.CommitLanguagesResponse_Language{
Name: lang,
Share: float32(100*count) / float32(total),
- Color: linguist.Color(lang),
+ Color: s.linguist.Color(lang),
Bytes: stats[lang],
}
resp.Languages = append(resp.Languages, l)
diff --git a/internal/gitaly/service/commit/languages_test.go b/internal/gitaly/service/commit/languages_test.go
index 7e09ba66b..54390a1de 100644
--- a/internal/gitaly/service/commit/languages_test.go
+++ b/internal/gitaly/service/commit/languages_test.go
@@ -5,12 +5,17 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
func TestLanguages(t *testing.T) {
- _, repo, _, client := setupCommitServiceWithRepo(t, true)
+ cfg, repo, _ := testcfg.BuildWithRepo(t, testcfg.WithRealLinguist())
+
+ serverSocketPath := startTestServices(t, cfg)
+
+ client := newCommitServiceClient(t, serverSocketPath)
request := &gitalypb.CommitLanguagesRequest{
Repository: repo,
diff --git a/internal/gitaly/service/commit/server.go b/internal/gitaly/service/commit/server.go
index 62c29b6b6..77d25709d 100644
--- a/internal/gitaly/service/commit/server.go
+++ b/internal/gitaly/service/commit/server.go
@@ -3,6 +3,7 @@ package commit
import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref"
"gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -12,6 +13,7 @@ type server struct {
cfg config.Cfg
locator storage.Locator
gitCmdFactory git.CommandFactory
+ linguist *linguist.Instance
}
var (
@@ -19,6 +21,6 @@ var (
)
// NewServer creates a new instance of a grpc CommitServiceServer
-func NewServer(cfg config.Cfg, locator storage.Locator, gitCmdFactory git.CommandFactory) gitalypb.CommitServiceServer {
- return &server{cfg: cfg, locator: locator, gitCmdFactory: gitCmdFactory}
+func NewServer(cfg config.Cfg, locator storage.Locator, gitCmdFactory git.CommandFactory, ling *linguist.Instance) gitalypb.CommitServiceServer {
+ return &server{cfg: cfg, locator: locator, gitCmdFactory: gitCmdFactory, linguist: ling}
}
diff --git a/internal/gitaly/service/commit/testhelper_test.go b/internal/gitaly/service/commit/testhelper_test.go
index f0815e916..91cf07f35 100644
--- a/internal/gitaly/service/commit/testhelper_test.go
+++ b/internal/gitaly/service/commit/testhelper_test.go
@@ -11,6 +11,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -28,6 +29,7 @@ func testMain(m *testing.M) int {
return m.Run()
}
+// setupCommitService makes a basic configuration and starts the service with the client.
func setupCommitService(t testing.TB) (config.Cfg, gitalypb.CommitServiceClient) {
cfg, _, _, client := setupCommitServiceCreateRepo(t, func(tb testing.TB, cfg config.Cfg) (*gitalypb.Repository, string, testhelper.Cleanup) {
return nil, "", func() {}
@@ -35,7 +37,10 @@ func setupCommitService(t testing.TB) (config.Cfg, gitalypb.CommitServiceClient)
return cfg, client
}
-func setupCommitServiceWithRepo(t testing.TB, bare bool) (config.Cfg, *gitalypb.Repository, string, gitalypb.CommitServiceClient) {
+// setupCommitServiceWithRepo makes a basic configuration, creates a test repository and starts the service with the client.
+func setupCommitServiceWithRepo(
+ t testing.TB, bare bool,
+) (config.Cfg, *gitalypb.Repository, string, gitalypb.CommitServiceClient) {
return setupCommitServiceCreateRepo(t, func(tb testing.TB, cfg config.Cfg) (*gitalypb.Repository, string, testhelper.Cleanup) {
if bare {
return gittest.CloneRepoAtStorage(tb, cfg.Storages[0], t.Name())
@@ -71,7 +76,10 @@ func startTestServices(t testing.TB, cfg config.Cfg) string {
listener, err := net.Listen("unix", serverSocketPath)
require.NoError(t, err)
- gitalypb.RegisterCommitServiceServer(server, NewServer(cfg, config.NewLocator(cfg), git.NewExecCommandFactory(cfg)))
+ ling, err := linguist.New(cfg)
+ require.NoError(t, err)
+
+ gitalypb.RegisterCommitServiceServer(server, NewServer(cfg, config.NewLocator(cfg), git.NewExecCommandFactory(cfg), ling))
go server.Serve(listener)
return "unix://" + serverSocketPath
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index f0d48f4a2..626dbfe46 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -89,7 +89,7 @@ func runOperationServiceServer(t *testing.T) (string, func()) {
gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(config.Config, hookManager, gitCmdFactory))
gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), repository.NewServer(config.Config, RubyServer, locator, txManager, gitCmdFactory))
gitalypb.RegisterRefServiceServer(srv.GrpcServer(), ref.NewServer(config.Config, locator, gitCmdFactory))
- gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), commit.NewServer(config.Config, locator, gitCmdFactory))
+ gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), commit.NewServer(config.Config, locator, gitCmdFactory, nil))
gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), ssh.NewServer(config.Config, locator, gitCmdFactory))
reflection.Register(srv.GrpcServer())
diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go
index df898e5ca..89df6b041 100644
--- a/internal/gitaly/service/register.go
+++ b/internal/gitaly/service/register.go
@@ -8,6 +8,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/blob"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/cleanup"
@@ -68,10 +69,11 @@ func RegisterAll(
locator storage.Locator,
conns *client.Pool,
gitCmdFactory git.CommandFactory,
+ ling *linguist.Instance,
) {
gitalypb.RegisterBlobServiceServer(grpcServer, blob.NewServer(rubyServer, cfg, locator, gitCmdFactory))
gitalypb.RegisterCleanupServiceServer(grpcServer, cleanup.NewServer(cfg, gitCmdFactory))
- gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer(cfg, locator, gitCmdFactory))
+ gitalypb.RegisterCommitServiceServer(grpcServer, commit.NewServer(cfg, locator, gitCmdFactory, ling))
gitalypb.RegisterDiffServiceServer(grpcServer, diff.NewServer(cfg, locator, gitCmdFactory))
gitalypb.RegisterNamespaceServiceServer(grpcServer, namespace.NewServer(locator))
gitalypb.RegisterOperationServiceServer(grpcServer, operations.NewServer(cfg, rubyServer, hookManager, locator, conns, gitCmdFactory))
diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go
index d22cdb51b..c645059b0 100644
--- a/internal/gitaly/service/repository/fetch_test.go
+++ b/internal/gitaly/service/repository/fetch_test.go
@@ -351,7 +351,7 @@ func runFullSecureServer(t *testing.T, locator storage.Locator) (*grpc.Server, s
require.NoError(t, err)
listener, addr := testhelper.GetLocalhostListener(t)
- service.RegisterAll(server, cfg, repository.RubyServer, hookManager, txManager, config.NewLocator(cfg), conns, gitCmdFactory)
+ service.RegisterAll(server, cfg, repository.RubyServer, hookManager, txManager, config.NewLocator(cfg), conns, gitCmdFactory, nil)
errQ := make(chan error)
// This creates a secondary GRPC server which isn't "secure". Reusing
diff --git a/internal/praefect/server_factory_test.go b/internal/praefect/server_factory_test.go
index e21a6d753..312d542c8 100644
--- a/internal/praefect/server_factory_test.go
+++ b/internal/praefect/server_factory_test.go
@@ -16,6 +16,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
gconfig "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/server"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/commit"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
@@ -40,10 +41,13 @@ func TestServerFactory(t *testing.T) {
gitalyServerFactory := server.NewGitalyServerFactory(cfg)
defer gitalyServerFactory.Stop()
+ ling, err := linguist.New(cfg)
+ require.NoError(t, err)
+
gitalySrv, err := gitalyServerFactory.Create(false)
require.NoError(t, err)
healthpb.RegisterHealthServer(gitalySrv, health.NewServer())
- gitalypb.RegisterCommitServiceServer(gitalySrv, commit.NewServer(cfg, locator, gitCmdFactory))
+ gitalypb.RegisterCommitServiceServer(gitalySrv, commit.NewServer(cfg, locator, gitCmdFactory, ling))
// start gitaly serving on public endpoint
gitalyListener, err := net.Listen(starter.TCP, "localhost:0")
diff --git a/internal/testhelper/testcfg/gitaly_builder.go b/internal/testhelper/testcfg/gitaly_builder.go
index 59890a5a2..ea7ce0b75 100644
--- a/internal/testhelper/testcfg/gitaly_builder.go
+++ b/internal/testhelper/testcfg/gitaly_builder.go
@@ -1,6 +1,7 @@
package testcfg
import (
+ "io/ioutil"
"os"
"path/filepath"
"testing"
@@ -33,6 +34,13 @@ func WithStorages(name string, names ...string) Option {
}
}
+// WithRealLinguist suppress stubbing of the linguist language detection.
+func WithRealLinguist() Option {
+ return func(builder *GitalyCfgBuilder) {
+ builder.realLinguist = true
+ }
+}
+
// NewGitalyCfgBuilder returns gitaly configuration builder with configured set of options.
func NewGitalyCfgBuilder(opts ...Option) GitalyCfgBuilder {
cfgBuilder := GitalyCfgBuilder{}
@@ -49,7 +57,8 @@ type GitalyCfgBuilder struct {
cfg config.Cfg
cleanups []testhelper.Cleanup
- storages []string
+ storages []string
+ realLinguist bool
}
func (gc *GitalyCfgBuilder) addCleanup(f testhelper.Cleanup) {
@@ -123,6 +132,14 @@ func (gc *GitalyCfgBuilder) Build(t testing.TB) config.Cfg {
}
}
+ if !gc.realLinguist {
+ if cfg.Ruby.LinguistLanguagesPath == "" {
+ // set a stub to prevent a long ruby process to run where it is not needed
+ cfg.Ruby.LinguistLanguagesPath = filepath.Join(root, "linguist_languages.json")
+ require.NoError(t, ioutil.WriteFile(cfg.Ruby.LinguistLanguagesPath, []byte(`{}`), 0655))
+ }
+ }
+
require.NoError(t, testhelper.ConfigureRuby(&cfg))
require.NoError(t, cfg.Validate())
diff --git a/internal/testhelper/testserver/gitaly.go b/internal/testhelper/testserver/gitaly.go
index 17ab6240c..2d1d98700 100644
--- a/internal/testhelper/testserver/gitaly.go
+++ b/internal/testhelper/testserver/gitaly.go
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/linguist"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/server"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service"
@@ -26,11 +27,13 @@ func RunGitalyServer(t *testing.T, cfg config.Cfg, rubyServer *rubyserver.Server
txManager := transaction.NewManager(cfg)
hookMgr := hook.NewManager(locator, txManager, hook.GitlabAPIStub, cfg)
gitCmdFactory := git.NewExecCommandFactory(cfg)
+ ling, err := linguist.New(cfg)
+ require.NoError(t, err)
srv, err := server.New(cfg.TLS.CertPath != "", cfg, testhelper.DiscardTestEntry(t))
require.NoError(t, err)
- service.RegisterAll(srv, cfg, rubyServer, hookMgr, txManager, locator, conns, gitCmdFactory)
+ service.RegisterAll(srv, cfg, rubyServer, hookMgr, txManager, locator, conns, gitCmdFactory, ling)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName(t)
listener, err := net.Listen("unix", serverSocketPath)