Skip to content

Commit 84bfd00

Browse files
authored
Fix TestSearchRepo by waiting till indexing is done (#7004)
* Fix TestSearchRepo by waiting till indexing is done * Update integrations/repo_search_test.go * changes as per @mrsdizzie
1 parent 1f84970 commit 84bfd00

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

integrations/repo_search_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
package integrations
66

77
import (
8+
"log"
89
"net/http"
910
"testing"
11+
"time"
12+
13+
"code.gitea.io/gitea/models"
1014

1115
"github.com/PuerkitoBio/goquery"
1216
"github.com/stretchr/testify/assert"
@@ -27,6 +31,27 @@ func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
2731
func TestSearchRepo(t *testing.T) {
2832
prepareTestEnv(t)
2933

34+
repo, err := models.GetRepositoryByOwnerAndName("user2", "repo1")
35+
assert.NoError(t, err)
36+
37+
models.UpdateRepoIndexer(repo)
38+
39+
log.Printf("Waiting for indexing\n")
40+
41+
i := 0
42+
for i < 60 {
43+
if repo.IndexerStatus != nil && len(repo.IndexerStatus.CommitSha) != 0 {
44+
break
45+
}
46+
time.Sleep(1 * time.Second)
47+
i++
48+
}
49+
if i < 60 {
50+
log.Printf("Indexing took: %ds\n", i)
51+
} else {
52+
log.Printf("Waited the limit: %ds for indexing, continuing\n", i)
53+
}
54+
3055
req := NewRequestf(t, "GET", "/user2/repo1/search?q=Description&page=1")
3156
resp := MakeRequest(t, req, http.StatusOK)
3257

0 commit comments

Comments
 (0)