Skip to content

Commit ade1839

Browse files
authored
Force remove test repo root path in case previous test is still locking it (#3528) (#3536)
Signed-off-by: Lauris Bukšis-Haberkorns <[email protected]>
1 parent c503eac commit ade1839

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

models/unit_tests.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path/filepath"
1111
"testing"
12+
"time"
1213

1314
"code.gitea.io/gitea/modules/setting"
1415

@@ -72,6 +73,18 @@ func createTestEngine(fixturesDir string) error {
7273
return InitFixtures(&testfixtures.SQLite{}, fixturesDir)
7374
}
7475

76+
func removeAllWithRetry(dir string) error {
77+
var err error
78+
for i := 0; i < 20; i++ {
79+
err = os.RemoveAll(dir)
80+
if err == nil {
81+
break
82+
}
83+
time.Sleep(100 * time.Millisecond)
84+
}
85+
return err
86+
}
87+
7588
// PrepareTestDatabase load test fixtures into test database
7689
func PrepareTestDatabase() error {
7790
return LoadFixtures()
@@ -81,7 +94,7 @@ func PrepareTestDatabase() error {
8194
// by tests that use the above MainTest(..) function.
8295
func PrepareTestEnv(t testing.TB) {
8396
assert.NoError(t, PrepareTestDatabase())
84-
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
97+
assert.NoError(t, removeAllWithRetry(setting.RepoRootPath))
8598
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
8699
assert.NoError(t, com.CopyDir(metaPath, setting.RepoRootPath))
87100
}

0 commit comments

Comments
 (0)