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>2020-11-17 15:55:07 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-11-19 16:35:56 +0300
commitc7edf9ae83fa39fd1152a27a52151d18704f97cb (patch)
treedb0976c34d6226e4b578a31df3e9a8bc944d9f16
parent4bc74487602107670dad6e3460fc747605470229 (diff)
testhelper: Move storage to temporary directory
Currently, our test storage is always located inside of the Gitaly repository in `internal/testhelper/testdata/data`. It's bad practice to write test data into the parent repository though, both because it's in fact hard to discover where data resides and also because any data which is accidentally left behind may impact future testruns. Personally, this happens quite regularly to myself and typically ends with a `git clean -dfx`. This commit instead moves our test storage into the global temporary test directory. Most importantly, this means that it's not possible anyomre to use `testhelper.TestRepository()`, as it would now return a repository which is not located inside the storage directory. But as all users of this function have been converted to `testhelper.NewTestRepo()` instead, we can now get rid of it. One may expect that the additional calls to `testhelper.NewTestRepo()` may slow down execution of our test suite as they'll cause the test repo to first get cloned. But in fact, the speedups we achieve by executing all repository-related operations in tmpfs greatly outweigh this. In a best-of-three for `make test-go`, test time was reduced from 1m14s to 32s: # Current master, storage in repository $ time make test-go >/dev/null real 1m14.064s user 3m37.406s sys 1m6.398s # This commit, storage in tmpfs $ time make test-go >/dev/null real 0m32.912s user 3m54.450s sys 0m58.274s User time has increased noticeably, which probably accounts for the additional invocations of git-clone(1). But system time has decreased, which results from the fact Git won't write to disk anymore. Overall, this is a speed improvement of nearly 60% while being impacted less by any leftover files in the Git repository.
-rw-r--r--internal/testhelper/testhelper.go42
1 files changed, 15 insertions, 27 deletions
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index df5528bb8..cdfbec1f5 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -47,9 +47,7 @@ import (
"google.golang.org/grpc/status"
)
-// TestRelativePath is the path inside its storage of the gitlab-test repo
const (
- TestRelativePath = "gitlab-test.git"
RepositoryAuthToken = "the-secret-token"
DefaultStorageName = "default"
testGitEnv = "testdata/git-env"
@@ -91,6 +89,10 @@ func Configure() func() {
config.Config.Storages = []config.Storage{
{Name: "default", Path: GitlabTestStoragePath()},
}
+ if err := os.Mkdir(config.Config.Storages[0].Path, 0755); err != nil {
+ os.RemoveAll(testDirectory)
+ log.Fatal(err)
+ }
config.Config.SocketPath = "/bogus"
config.Config.GitlabShell.Dir = "/"
@@ -138,11 +140,10 @@ func MustReadFile(t testing.TB, filename string) []byte {
// GitlabTestStoragePath returns the storage path to the gitlab-test repo.
func GitlabTestStoragePath() string {
- _, currentFile, _, ok := runtime.Caller(0)
- if !ok {
- log.Fatal("Could not get caller info")
+ if testDirectory == "" {
+ log.Fatal("you must call testhelper.Configure() before GitlabTestStoragePath()")
}
- return filepath.Join(filepath.Dir(currentFile), "testdata", "data")
+ return filepath.Join(testDirectory, "storage")
}
// GitalyServersMetadata returns a metadata pair for gitaly-servers to be used in
@@ -192,25 +193,6 @@ func isValidRepoPath(absolutePath string) bool {
return true
}
-// TestRepository returns the `Repository` object for the gitlab-test repo.
-// Tests should be calling this function instead of cloning the repo themselves.
-// Tests that involve modifications to the repo should copy/clone the repo
-// via the `Repository` returned from this function.
-func TestRepository() *gitalypb.Repository {
- repo := &gitalypb.Repository{
- StorageName: "default",
- RelativePath: TestRelativePath,
- GlRepository: GlRepository,
- }
-
- storagePath, _ := config.Config.StoragePath(repo.GetStorageName())
- if !isValidRepoPath(filepath.Join(storagePath, repo.RelativePath)) {
- panic("Test repo not found, did you run `make prepare-tests`?")
- }
-
- return repo
-}
-
// RequireGrpcError asserts the passed err is of the same code as expectedCode.
func RequireGrpcError(t testing.TB, err error, expectedCode codes.Code) {
t.Helper()
@@ -519,7 +501,8 @@ func Context(opts ...ContextOpt) (context.Context, func()) {
// CreateRepo creates a temporary directory for a repo, without initializing it
func CreateRepo(t testing.TB, storagePath, relativePath string) *gitalypb.Repository {
- require.NoError(t, os.MkdirAll(filepath.Dir(storagePath), 0755), "making repo parent dir")
+ repoPath := filepath.Join(storagePath, relativePath, "..")
+ require.NoError(t, os.MkdirAll(repoPath, 0755), "making repo parent dir")
return &gitalypb.Repository{
StorageName: "default",
RelativePath: relativePath,
@@ -578,7 +561,12 @@ func NewTestRepoWithWorktree(t testing.TB) (repo *gitalypb.Repository, repoPath
// testRepositoryPath returns the absolute path of local 'gitlab-org/gitlab-test.git' clone.
// It is cloned under the path by the test preparing step of make.
func testRepositoryPath(t testing.TB) string {
- path := filepath.Join(GitlabTestStoragePath(), TestRelativePath)
+ _, currentFile, _, ok := runtime.Caller(0)
+ if !ok {
+ log.Fatal("could not get caller info")
+ }
+
+ path := filepath.Join(filepath.Dir(currentFile), "testdata", "data", "gitlab-test.git")
if !isValidRepoPath(path) {
t.Fatalf("local clone of 'gitlab-org/gitlab-test.git' not found in %q, did you run `make prepare-tests`?", path)
}