From a32b0da87c10bb628a9d2203b700f0683e1ae966 Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Mon, 16 Mar 2026 16:48:11 +0100 Subject: [PATCH] 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 Co-authored-by: Shiny Nematoda Co-committed-by: Shiny Nematoda --- modules/indexer/issues/indexer.go | 7 ++++++- modules/indexer/issues/indexer_test.go | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go index 81ffcaaf5d..2f70cf7a69 100644 --- a/modules/indexer/issues/indexer.go +++ b/modules/indexer/issues/indexer.go @@ -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 { diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 2d7aa71236..60c46d9a2c 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -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})