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})