Skip to content

Add RavenDB index deployment tests and approve index definitions as deployed - #6133

Open
danielmarbach wants to merge 5 commits into
masterfrom
cherry-pick-index-schema-drift
Open

danielmarbach wants to merge 5 commits into
masterfrom
cherry-pick-index-schema-drift

Conversation

@danielmarbach

@danielmarbach danielmarbach commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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.md change.

What changes

  • IndexDeploymentTests in both RavenDB persistence test projects deploy each index on its own to a new database. IndexDeployment sends 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 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.
  • IndexDefinitionTests replaces IndexDefinitionApprovals from 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/IndexDefinitionText stays 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.
  • SharedEmbeddedServer publishes the test server only after its setup completes, and disposes it when the setup fails. ScratchDatabase and CleanDatabaseFixture dispose 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 Type and SourceType lines.

Why the approvals deploy to a Lucene database

Both approvals deploy to a database created with the Lucene settings that DatabaseSetup uses for new databases. The indexes inherit the search engine, so IndexDeployment adds nothing, and a Configuration line 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. IndexDeployment then set Lucene on every index, and the approved file carried that line on each of them. I tried what that hides: I set SearchEngineType = Lucene in one index definition per persister. The audit approval still passed. The primary approval, which already deployed to a Lucene database, failed with one new Configuration line. The comment on rule 4 in IndexDeployment says 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 audit IndexDeploymentTests still deploy to a database without a setting and assert Lucene there.

Differences from #6049

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 names IndexDefinitionTests, says why the approval deploys to a Lucene database, and describes IndexDeploymentTests.
  • 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.

…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.
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.

1 participant