Skip to content

Commit efd34d0

Browse files
authored
Prevent intermittent failures in RepoIndexerTest (#19225 #19229) (#19228)
Backport #19225 Backport #19229 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. Fix #19162 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 2ec2935 commit efd34d0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

modules/indexer/stats/indexer_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
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/git"
16+
"code.gitea.io/gitea/modules/queue"
1417
"code.gitea.io/gitea/modules/setting"
1518

1619
_ "code.gitea.io/gitea/models"
@@ -24,6 +27,10 @@ func TestMain(m *testing.M) {
2427
}
2528

2629
func TestRepoStatsIndex(t *testing.T) {
30+
if err := git.Init(context.Background()); !assert.NoError(t, err) {
31+
return
32+
}
33+
2734
assert.NoError(t, unittest.PrepareTestDatabase())
2835
setting.Cfg = ini.Empty()
2936

@@ -32,10 +39,14 @@ func TestRepoStatsIndex(t *testing.T) {
3239
err := Init()
3340
assert.NoError(t, err)
3441

35-
time.Sleep(5 * time.Second)
36-
3742
repo, err := repo_model.GetRepositoryByID(1)
3843
assert.NoError(t, err)
44+
45+
err = UpdateRepoIndexer(repo)
46+
assert.NoError(t, err)
47+
48+
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
49+
3950
status, err := repo_model.GetIndexerStatus(repo, repo_model.RepoIndexerTypeStats)
4051
assert.NoError(t, err)
4152
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.CommitSha)

0 commit comments

Comments
 (0)