Repository navigation
Add RavenDB index deployment tests and approve index definitions as deployed - #6133
Conversation
5787b40 to
4d664f8
Compare
| databaseRecord.Settings.Add("Indexing.Auto.SearchEngineType", "Lucene"); | ||
| databaseRecord.Settings.Add("Indexing.Static.SearchEngineType", "Lucene"); |
There was a problem hiding this comment.
Considering that the tests use our IndexDeployment.CreateIndexesAsync stuff, which sets the search engine explicitly, we probably don't need these settings here.
| databaseRecord.Settings.Add("Indexing.Auto.SearchEngineType", "Lucene"); | |
| databaseRecord.Settings.Add("Indexing.Static.SearchEngineType", "Lucene"); |
There was a problem hiding this comment.
Fair enough. You are right this is probably overkill.
There was a problem hiding this comment.
@mauroservienti I remembered again why I added it. When it is not set on the scratch database, it doesn't count as inherited, and then the approval file shows it in all index definitions. I was thinking this is not what we want since we are no longer setting at the level of the index, and it would suggest it is at the level of the index. Thoughts?
There was a problem hiding this comment.
My undersanding is that both options are possible:
ServiceControl/src/ServiceControl.RavenDB/IndexDeployment.cs
Lines 89 to 105 in 7b41634
There was a problem hiding this comment.
I get that, but for the approval tests we need to stick to a variant. Which would you prefer? Otherwise I need to create test cases for all variants which seems a hazzle
There was a problem hiding this comment.
Okay, you're right, now I get it. We're not testing; we're setting the right indexing engine. We're testing that the definition is stable.
…letes GetInstance assigned the static field before the server was reachable and before the database setup finished, while the fast path returned it without taking the semaphore. A test running in parallel could use the server too early and fail with a connection refused error in its setup.
IndexDeployment sends all indexes of a persister in one call, so an index the server rejects blocks the deployment of every other index. These tests deploy each index on its own to a new database and check that it is in the Normal state and uses Lucene. The audit tests also query each index and check the analyzer the server stores for the full-text field. The tests come from the characterization tests in #6049. They use IndexDeployment.FindIndexes and DocumentStoreConventions.Create, which did not exist when that pull request was written.
The index definition approvals now deploy the indexes to a new database on the embedded server before they render the definitions. The approved text is what the server received, including a search engine that IndexDeployment sets on an index. The rendering adds the index type, the source type, compound fields, the archived data behavior, the reduce output index, and every field option the client serializes. IndexDefinitionTests replaces IndexDefinitionApprovals from #6013 in both RavenDB persistence test projects. Both tests share the renderer in TestHelper, so the audit approval covers the same properties as the primary one. The approved maps, reduces, and field options are the same as before. The tests come from the characterization tests in #6049.
The audit approval deployed to a database without a search engine setting, so IndexDeployment set Lucene on every index and the approved file carried that line on each of them. With the line always present, an index definition that starts to set its own search engine left the approved file unchanged, although RavenDB rebuilds such an index on a database that defaults to Lucene. The audit approval now deploys to a database created with the Lucene settings that DatabaseSetup uses, as the primary approval does. The indexes inherit the search engine, so a Configuration line in an approved file comes from the index definition itself.
…fails SharedEmbeddedServer left the server running when the connection or the database setup failed after the start. The server was not published, so every later caller tried to start it again and failed with "The server was already started", which hid the first error, and Stop did not dispose it. The server is now disposed when its setup fails, so the next caller starts a new one. ScratchDatabase and CleanDatabaseFixture dispose the document store when creating the database fails or deleting it throws. The audit index searches pass the test timeout token, so a stalled query ends with the test timeout.
4d664f8 to
582d39f
Compare
This brings the RavenDB index tests from #6049 to master. #6049 is not being merged yet. Its tests cover two things master lacks: a check that each index deploys on its own, and an approval of the index definitions as deployed. Only tests, test helpers, and
docs/testing.mdchange.What changes
IndexDeploymentTestsin both RavenDB persistence test projects deploy each index on its own to a new database.IndexDeploymentsends all indexes of a persister in one call, so an index the server rejects blocks every other index. Each test checks that the index is in theNormalstate and uses Lucene. The audit tests also query each index and check the analyzer the server stores for the full-text field.IndexDefinitionTestsreplacesIndexDefinitionApprovalsfrom Approve RavenDB index definitions to catch changes that trigger a rebuild #6013 in both projects. The test deploys the indexes to a new database first and then approves the definitions, so the approved text is what a new installation deploys.TestHelper/IndexDefinitionTextstays the one renderer for both projects. It now also prints the index type, the source type, compound fields, the archived data behavior, and the reduce output index. It prints field options and additional assemblies as JSON, which adds the spatial bounds and the assembly usings that the earlier renderer left out.SharedEmbeddedServerpublishes the test server only after its setup completes, and disposes it when the setup fails.ScratchDatabaseandCleanDatabaseFixturedispose their document store when creating or deleting the database fails.The approved files contain the same index names, map and reduce text, and field options as the files they replace. The additions are the
TypeandSourceTypelines.Why the approvals deploy to a Lucene database
Both approvals deploy to a database created with the Lucene settings that
DatabaseSetupuses for new databases. The indexes inherit the search engine, soIndexDeploymentadds nothing, and aConfigurationline in an approved file can only come from the index definition.In #6049 the audit approval deployed to a database without a search engine setting.
IndexDeploymentthen set Lucene on every index, and the approved file carried that line on each of them. I tried what that hides: I setSearchEngineType = Lucenein one index definition per persister. The audit approval still passed. The primary approval, which already deployed to a Lucene database, failed with one newConfigurationline. The comment on rule 4 inIndexDeploymentsays RavenDB rebuilds an index when a search engine is added to its configuration. That applies also when the engine is the same. I did not test that rebuild against a server.The rules that set Lucene on an index keep their own tests in the audit
IndexSetupTests. The auditIndexDeploymentTestsstill deploy to a database without a setting and assert Lucene there.Differences from #6049
IndexDeployment.FindIndexesand the shared renderer. In Update RavenDB to 7.2.7 #6049 it had a fixed list of four indexes and rendered fewer properties than Approve RavenDB index definitions to catch changes that trigger a rebuild #6013 already did.IndexDeployment.FindIndexesreplacesPrimaryIndexes.cs. Master gainedFindIndexesafter Update RavenDB to 7.2.7 #6049 was written.DocumentStoreConventions.Create(), so a change to the conventions still fails the approval.The other characterization tests stay in #6049: expiration metadata, server JSON contracts, throughput time series, the Lucene and Corax query tests, server logging, and
MessagesViewIndexTests.Docs
docs/testing.md: updated. It namesIndexDefinitionTests, says why the approval deploys to a Lucene database, and describesIndexDeploymentTests.docs/decisions/2026-10-20-ravendb-index-search-engine-and-rebuilds.md: reviewed, no change. It describes an approval test that renders every index definition the persisters deploy, which still holds.docs/README.md: reviewed, no change. No canonical source was added or retired.Records consulted: #6049, #6013, the ADR above, and
docs/testing.md. Internal context was consulted and has no record on these tests.