Skip to content

testhelper: Move storage to temporary directory

Patrick Steinhardt requested to merge pks-tests-storage-in-tmpfs into master

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.

Merge request reports