From ade183957d2af46e3508fd7e3930b61278b4ab19 Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Mon, 19 Feb 2018 08:29:37 +0200 Subject: [PATCH] Force remove test repo root path in case previous test is still locking it (#3528) (#3536) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lauris Bukšis-Haberkorns --- models/unit_tests.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/models/unit_tests.go b/models/unit_tests.go index 8fdeb0b14..962b1a494 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)) }