Skip to content

Commit 6afe913

Browse files
committed
Prevent intermittent failures in RepoIndexerTest (go-gitea#19225)
Backport go-gitea#19225 The RepoIndexerTest is failing with considerable frequency due to a race inherrent in its design. This PR adjust this test to avoid the reliance on waiting for the populate repo indexer to run and forcibly adds the repo to the queue. It then flushes the queue. It may be worth separating out the tests somewhat by testing the Index function directly away from the queue however, this forceful method should solve the current problem. Signed-off-by: Andrew Thornton <[email protected]>
1 parent a13d64b commit 6afe913

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/indexer/stats/indexer_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
package stats
66

77
import (
8+
"context"
89
"path/filepath"
910
"testing"
1011
"time"
1112

1213
repo_model "code.gitea.io/gitea/models/repo"
1314
"code.gitea.io/gitea/models/unittest"
15+
"code.gitea.io/gitea/modules/queue"
1416
"code.gitea.io/gitea/modules/setting"
1517

1618
_ "code.gitea.io/gitea/models"
@@ -32,10 +34,14 @@ func TestRepoStatsIndex(t *testing.T) {
3234
err := Init()
3335
assert.NoError(t, err)
3436

35-
time.Sleep(5 * time.Second)
36-
3737
repo, err := repo_model.GetRepositoryByID(1)
3838
assert.NoError(t, err)
39+
40+
err = UpdateRepoIndexer(repo)
41+
assert.NoError(t, err)
42+
43+
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
44+
3945
status, err := repo_model.GetIndexerStatus(repo, repo_model.RepoIndexerTypeStats)
4046
assert.NoError(t, err)
4147
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.CommitSha)

0 commit comments

Comments
 (0)