test: attempt to fix flaky TestBleveDeleteIssue (#11686)

Wait till the indexer has been fully initialized

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11686
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
Shiny Nematoda 2026-03-16 16:48:11 +01:00 committed by Mathieu Fenniak
parent 61fe3bb8ff
commit a32b0da87c
2 changed files with 8 additions and 3 deletions

View file

@ -61,10 +61,12 @@ func init() {
// InitIssueIndexer initialize issue indexer, syncReindex is true then reindex until
// all issue index done.
func InitIssueIndexer(syncReindex bool) {
// The return value is a done channel that signals that the indexer can be safely used.
func InitIssueIndexer(syncReindex bool) <-chan struct{} {
ctx, _, finished := process.GetManager().AddTypedContext(context.Background(), "Service: IssueIndexer", process.SystemProcessType, false)
indexerInitWaitChannel := make(chan time.Duration, 1)
done := make(chan struct{}, 1)
// Create the Queue
issueIndexerQueue = queue.CreateUniqueQueue(ctx, "issue_indexer", getIssueIndexerQueueHandler(ctx))
@ -136,6 +138,7 @@ func InitIssueIndexer(syncReindex bool) {
indexerInitWaitChannel <- time.Since(start)
close(indexerInitWaitChannel)
close(done)
}()
if syncReindex {
@ -163,6 +166,8 @@ func InitIssueIndexer(syncReindex bool) {
}
}()
}
return done
}
func getIssueIndexerQueueHandler(ctx context.Context) func(items ...*IndexerMetadata) []*IndexerMetadata {

View file

@ -30,7 +30,7 @@ func TestDBSearchIssues(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
defer test.MockVariableValue(&setting.Indexer.IssueType, "db")()
InitIssueIndexer(true)
<-InitIssueIndexer(true)
t.Run("search issues with keyword", searchIssueWithKeyword)
t.Run("search issues in repo", searchIssueInRepo)
@ -426,7 +426,7 @@ func TestBleveDeleteIssue(t *testing.T) {
tmp := t.TempDir()
defer test.MockVariableValue(&setting.Indexer.IssuePath, filepath.Join(tmp, "indexers/issues.bleve"))()
defer test.MockVariableValue(&setting.Indexer.IssueType, "bleve")()
InitIssueIndexer(false)
<-InitIssueIndexer(false)
ctx := t.Context()
issue := unittest.AssertExistsAndLoadBean(t, &issues.Issue{ID: 1})