diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-03-15 15:10:38 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-03-18 12:49:31 +0300 |
commit | 63c55949d54543fce205c0f750f8fc502ed9566a (patch) | |
tree | a26b220fde2aea0495789d584b35432bc6212751 /internal/praefect/server_factory_test.go | |
parent | 2093a05fa4214e69abc75eacea26e926266264b1 (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
Diffstat (limited to 'internal/praefect/server_factory_test.go')
-rw-r--r-- | internal/praefect/server_factory_test.go | 6 |
1 files changed, 5 insertions, 1 deletions
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") |