Skip to content

CBG-5160 stub index creation for test purposes#8056

Merged
bbrks merged 4 commits intomainfrom
CBG-5160
Feb 25, 2026
Merged

CBG-5160 stub index creation for test purposes#8056
bbrks merged 4 commits intomainfrom
CBG-5160

Conversation

@torcolvin
Copy link
Copy Markdown
Collaborator

CBG-5160 stub index creation for test purposes

Creating and destroying indexes takes a lot of time for N1QL nodes. Sometimes they give up after 1 minute when running full integration tests.

I don't think to test the behavior of the AsyncIndexInitManager that we need to actually create the indexes, since we aren't verifying that they are being created. There is code elsewhere that does test whether these are created.

Note:

  • All tests in rest/indextest drop all indexes as part of the bucket readier. They will get recreated when a database starts up. I would propose to move the tests that use SetInitializeIndexesFunc to rest package or something that isn't dropping indexes each time.
  • Fixed a bug that I should pull into a separate ticket where DatabaseContext.AsyncIndexInitManager would be nil if the database was started offline and cause a panic.
  • There are still slow tests in indextest which are candidates for mocking, especially TestChangeIndexPartitions. The first half of this test would work for mocking, but the second part of the test what tests _post_upgrade removal process can't be tested using this framework, so I did not modify it.

I'm open to this not being the right thing to do, but I'm reluctant to increase the wait time for indexes to be created above 1 minute because I think it could take a really long time and our integration tests are now pushing two hours. I don't think the real creation of these indexes is that useful, we do test the partitioned index creation in db/indextest package. I think it would be fine to leave a small number of these tests preesent.

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

Copilot AI review requested due to automatic review settings February 4, 2026 18:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces stubbed index creation functions for test purposes to improve integration test performance. Creating and destroying indexes on N1QL nodes is time-consuming and causing tests to timeout after 1 minute during full integration test runs.

Changes:

  • Adds injectable InitializeIndexesFunc to DatabaseInitManager and DatabaseInitWorker for test stubbing
  • Introduces noop index creation functions (getNoopInitializeIndexes and getNoopBlockingInitializeIndexes) to avoid actual index operations
  • Fixes bug where DatabaseContext.AsyncIndexInitManager was nil when database started offline, causing potential panics

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
rest/indextest/index_init_api_test.go Updates tests to use stubbed index creation functions and replaces manual polling with helper function
rest/database_init_manager.go Adds InitializeIndexesFunc injection mechanism for test stubbing
db/database.go Moves AsyncIndexInitManager initialization to NewDatabaseContext to prevent nil panics
base/util_testing.go Improves error reporting in DropAllIndexes to show remaining indexes on failure

Comment thread rest/indextest/index_init_api_test.go
Comment thread rest/indextest/index_init_api_test.go
Comment thread rest/indextest/index_init_api_test.go
Comment thread rest/indextest/index_init_api_test.go
Comment thread db/database.go
@bbrks bbrks assigned torcolvin and unassigned bbrks Feb 24, 2026
@torcolvin torcolvin assigned bbrks and unassigned torcolvin Feb 24, 2026
@torcolvin torcolvin requested a review from bbrks February 24, 2026 15:29
@bbrks bbrks merged commit 935a975 into main Feb 25, 2026
50 checks passed
@bbrks bbrks deleted the CBG-5160 branch February 25, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants