summaryrefslogtreecommitdiffstats
path: root/models/unit_tests.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-02-18 23:19:40 +0200
committerGitHub <noreply@github.com>2018-02-18 23:19:40 +0200
commit3a9c6988216968b8c4ec0082ce148819ae1e9069 (patch)
treee58bc0060d636c097addaf4d7f879aa6bd6dc64f /models/unit_tests.go
parentae30315a62644774756df64af0ca1ef405853a57 (diff)
downloadgitea-3a9c6988216968b8c4ec0082ce148819ae1e9069.tar.gz
gitea-3a9c6988216968b8c4ec0082ce148819ae1e9069.zip
Force remove test repo root path in case previous test is still locking it (#3528)
Signed-off-by: Lauris Bukšis-Haberkorns <lauris@nix.lv>
Diffstat (limited to 'models/unit_tests.go')
-rw-r--r--models/unit_tests.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/models/unit_tests.go b/models/unit_tests.go
index 8fdeb0b14b..962b1a4944 100644
--- a/models/unit_tests.go
+++ b/models/unit_tests.go
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"testing"
+ "time"
"code.gitea.io/gitea/modules/setting"
@@ -72,6 +73,18 @@ func createTestEngine(fixturesDir string) error {
return InitFixtures(&testfixtures.SQLite{}, fixturesDir)
}
+func removeAllWithRetry(dir string) error {
+ var err error
+ for i := 0; i < 20; i++ {
+ err = os.RemoveAll(dir)
+ if err == nil {
+ break
+ }
+ time.Sleep(100 * time.Millisecond)
+ }
+ return err
+}
+
// PrepareTestDatabase load test fixtures into test database
func PrepareTestDatabase() error {
return LoadFixtures()
@@ -81,7 +94,7 @@ func PrepareTestDatabase() error {
// by tests that use the above MainTest(..) function.
func PrepareTestEnv(t testing.TB) {
assert.NoError(t, PrepareTestDatabase())
- assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
+ assert.NoError(t, removeAllWithRetry(setting.RepoRootPath))
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
assert.NoError(t, com.CopyDir(metaPath, setting.RepoRootPath))
}