Running Integration Tests
Integration tests run from the Integration/Client project and can execute in either in-process or out-of-process mode. They require Docker to be running on your machine.
To attribute an existing CI invocation without changing its test selection or lifecycle, see Interpreting Integration Timings.
When you provide no runtime arguments, the suite defaults to:
- mode:
outofprocess - database:
mongodb
Switching off an xUnit integration tier
Section titled “Switching off an xUnit integration tier”xUnit can initialize a class fixture even when every fact in the class is skipped. In a context derived from ChronicleClientFixture<TChronicleFixture> or either Specification variant, override ShouldBootstrap with the same predicate that gates your facts, for example protected override bool ShouldBootstrap => TierIsEnabled;. Keep that predicate stable for the context’s lifetime. The default is true.
When it is false, the context skips OnBeforeInitializeAsync, including host bootstrap and storage, grain and client reset, as well as OnInitializeAsync and the matching scenario, service-scope, host and storage cleanup. Overriding only OnInitializeAsync does not stop the earlier bootstrap and reset. This applies to both the xUnit v2 and v3 packages, shared and per-fact context lifecycles, and custom storage configurations that use these base classes.
The gate controls the context lifecycle, not construction of its backing fixture. ChronicleFixture starts its container eagerly in its constructor, before the context receives it. ChronicleInProcessFixture starts MongoDB this way; ChronicleOutOfProcessFixture starts the Chronicle development container. If xUnit registers a backing fixture, for example as a collection fixture, skipping the context cannot undo that startup. To keep a disabled tier container-free, exclude its backing fixture registration or keep that tier out of the run. The gate does not change how you select or skip facts, or prevent explicit access to host and storage APIs.
When CI runs integration
Section titled “When CI runs integration”Pull-request pushes affecting the build paths run the Release build, specs, and a local Docker image build from Release binaries without pushing it, not the Docker integration suites. Run the relevant integration namespace locally before requesting CI integration. The hot-core gate fails on hot-core PRs until Requested Integration passes for the current head commit; its ordinary PR check does not run the matrix. Hot core includes the kernel Core, Concepts, Storage, Storage.InMemory, Storage.MongoDB and Storage.Sql runtime trees, plus Infrastructure/Changes; spec trees are excluded.
Apply the run-integration label to a pull request to start the separate Requested Integration workflow, even for a documentation-only PR. It builds the commit and runs specs, API and MongoDB integration, and one client integration matrix: MongoDB and SQLite normally, every backend when the PR touches the hot core. The separately named requested hot-core gate requires that full matrix to pass. The ordinary hot-core-gate check turns green automatically when that requested run passes, without a new push; for pushes to a PR that already carries the label, the requested run is part of the same Hot Core Gate run, so the check reports its verdict directly. While the label remains applied, each new push or reopening automatically starts integration for the current head commit and cancels any older requested run for that PR. A push invalidates the previous commit’s evidence; there is no need to remove and re-add the label. Other labels do not start integration or replace the ordinary PR check results.
The existing nightly schedule on main and manual workflow_dispatch run the full client backend matrix. Main-branch pushes do not run integration; nightly coverage handles main. A fork PR cannot push the integration image with its read-only token; labeling it fails the requested gate with an “unavailable” notice instead of running integration, so a fork PR can never satisfy that gate. The ordinary hot-core gate also fails closed for forks. Ask a maintainer to dispatch Hot Core Gate on a trusted branch containing those changes and merge with bypass.
For a labeled event, the image-push guard checks github.actor—the account that applied the label, not the PR author. A maintainer-labeled Dependabot PR therefore attempts the image push; if GitHub supplies a read-only token, the requested run fails rather than silently skipping the client matrix.
How the CI run is shaped
Section titled “How the CI run is shaped”A full run starts about 130 client shards and several other lanes, and the wall clock of that run is what a reviewer waits for. Three things keep it short and its concurrency bounded:
- Concurrency caps. Each matrix sets
max-parallelso a run holds a bounded number of runner slots: 34 for the client shards, 2 for the kernel shards, and 1 each for clustering, SQL clustering, the SQL RollingUpgrade lane and the Neo4j lanes. The MongoDB and API integration jobs are single jobs.test-sparse-integration-workflows.pypins the values. The caps are a per-run bound, not a guarantee about other work in the organization. - Longest shards first. GitHub starts matrix jobs in the order of the generated matrix, so
generate-integration-matrix.pyorders the client matrix by the measured job time in.github/scripts/integration-shard-order.json, slowest first. The order never changes which shards run, so a stale table only costs wall time. Refresh it from a recent all-provider run when shard times move; a shard the table does not list starts after the listed ones.for_ReadModelsandfor_EventStoreSubscriptionsrun as two shards each because one job of each was the longest in a run. - Parallel coverage merge. Merging the Cobertura files of one run in a single job took about nine minutes after the last lane finished. The
coverage-partialjob merges them in six groups at once (client MongoDB in-process, client MongoDB out-of-process, SQLite, PostgreSQL and SQL Server shards, and everything else), andcoverage-merge-and-cachemerges the six results. The groups together match everycoverage-results-*artifact exactly once, which a spec checks; an artifact no group names would drop that lane from coverage without failing the run. A group with no artifacts, such as the PostgreSQL group on a pull request run, is skipped. Both jobs still require every spec and lane to succeed.
Prerequisites
Section titled “Prerequisites”- Docker running locally
- .NET SDK (version matches
global.json) - Built binaries — run
dotnet buildfrom the repository root before running tests for the first time, or after any source change
Local kernel images
Section titled “Local kernel images”Building the repository without -p:DisableDockerBuild=true also builds the kernel images the suites run. Build first so the tests use your working tree:
| Image | Built by | Dockerfile | MongoDB |
|---|---|---|---|
cratis/chronicle:local-development-slim |
Integration/Client and Integration/SqlClustering |
Docker/LocalSlim |
Not embedded |
cratis/chronicle:local-development |
Integration/Api and Benchmarks |
Docker/Local |
Embedded |
A local build never produces a published name (latest* or <version>*), so it cannot replace the registry image other projects on the machine use. CI enforces this. CRATIS_CHRONICLE_LOCAL_IMAGE overrides the image name for both the build and the tests. Use -p:DisableDockerBuild=true to skip the image build.
Builds made before this change may have left cratis/chronicle:latest-development built from a working tree. Remove that stale local image and pull the published image again:
docker image rm cratis/chronicle:latest-developmentdocker pull cratis/chronicle:latest-developmentAlso remove cratis/chronicle:latest if you ever ran dockerize.sh.
Test Suites
Section titled “Test Suites”| Suite | Project | Description |
|---|---|---|
| Client | Integration/Client |
Runs the shared .NET integration specifications in either inprocess or outofprocess mode, with runtime storage selected through command-line arguments. |
| Graph projections | Integration/Client/GraphProjections |
Projects events onto a real Neo4j server and reads the graph back with Cypher. See Graph projection specifications. |
| Neo4j storage | Integration/Neo4j |
Exercises the Neo4j graph sink, connections and database creation directly against a Neo4j container, with no kernel or silo, the way Integration/MongoDB exercises MongoDB storage. See Neo4j storage specifications. |
| API (out-of-process) | Integration/Api |
Runs a full Chronicle server via Docker and tests the HTTP/gRPC client against it. |
Graph projection specifications
Section titled “Graph projection specifications”The GraphProjections namespace of the Client suite starts neo4j:5-community beside the other containers, with a password generated for every run, and connects the silo of the client to it through Cratis:Chronicle:Neo4j. Every specification starts on an empty graph and reads the result back from Neo4j with Cypher of its own, never through the sink under test.
The Community edition has one user database, so the sink runs in single database mode and stamps the namespace on every node and edge. Set CHRONICLE_NEO4J_DATABASE_MODE=PerNamespace and CHRONICLE_NEO4J_IMAGE to run the same specifications against a server with multiple databases. In that mode the sink creates one database per event store and namespace, and every specification starts by clearing all of them.
Multiple databases need the Enterprise edition, so CI runs one extra in-process lane against MongoDB with CHRONICLE_NEO4J_IMAGE=neo4j:5-enterprise and PerNamespace. When the image name contains enterprise, the fixture starts the container with NEO4J_ACCEPT_LICENSE_AGREEMENT=eval, which accepts the Neo4j Evaluation Agreement. This is temporary; the license follow-up is tracked in Cratis/Chronicle#5739. Every other lane stays on neo4j:5-community in single database mode.
The same organization is declared with model-bound attributes, with the fluent builder and in the projection declaration language, and each declaration must leave the same graph behind. CI runs the namespace in process against MongoDB and out of process against every other storage backend the run selects.
Neo4j storage specifications
Section titled “Neo4j storage specifications”Integration/Neo4j is the storage level of the graph integration specifications. It starts one Neo4j container for the run and uses Neo4jGraphSink, Neo4jGraphSinkFactory and Neo4jConnections the way the kernel does, with no kernel, no silo and no client. Every specification gets a namespace of its own, writes through the sink, and reads the result back with Cypher through a driver that is not the one under test. What it leaves behind is removed again: the nodes of its namespaces in single database mode, the databases of its namespaces otherwise.
The two levels answer different questions:
| Level | Project | Proves |
|---|---|---|
| Storage | Integration/Neo4j |
What the sink does on a real server: upserts, the watermark that makes writes idempotent, deletes with and without detach, edge identity, replay mark and sweep, namespace isolation, the constraints, database creation and naming, value round trips. |
| Client projection | Integration/Client/GraphProjections |
That events projected by the kernel end up as the graph a declaration describes, whichever of model-bound attributes, the fluent builder or the projection declaration language declares it. |
The server and its generated password are shared with the Client suite through Integration/Shared/Neo4jGraphServer.cs. The password is never committed or put in a command line the container tooling logs. Run the suite locally with Docker running:
dotnet build Integration/Neo4j/Neo4j.csproj -p:DisableDockerBuild=truedotnet Integration/Neo4j/bin/Debug/net11.0/Cratis.Chronicle.Neo4j.Integration.dllIt runs against neo4j:5-community in single database mode, where every namespace shares one database and is stamped on every node and edge. To run it with a database per namespace, point it at an Enterprise image, which accepts the Neo4j Evaluation Agreement for now (see Cratis/Chronicle#5739):
CHRONICLE_NEO4J_IMAGE=neo4j:5-enterprise CHRONICLE_NEO4J_DATABASE_MODE=PerNamespace \ dotnet Integration/Neo4j/bin/Debug/net11.0/Cratis.Chronicle.Neo4j.Integration.dllAsking for PerNamespace on an image with one database fails the fixture with a message naming the image. Specifications whose outcome depends on the mode assert the outcome of the mode they run in, so both lanes run the same specifications.
CI runs the project as the neo4j job of the build workflow, once per lane: neo4j:5-community with Single, and neo4j:5-enterprise with PerNamespace. Like the MongoDB integration job, it needs no kernel image.
Checking packed test-package startup
Section titled “Checking packed test-package startup”Before publishing locally packed packages, check startup from outside the repository:
bash .github/scripts/verify-consumer-smoke.sh "$CHRONICLE_VERSION" "$LOCAL_PACKAGE_FEED"Set CHRONICLE_VERSION to the candidate version and LOCAL_PACKAGE_FEED to the directory containing its NuGet packages. The check requires the .NET SDK and NuGet access, but not Docker. It starts two separate applications: one using Chronicle.Testing with Arc.Chronicle.Testing, and one using Chronicle.XUnit.Integration without either Testing package. Both must complete AddCratisArcCore() type discovery.
Each test package carries its own embedded kernel runtime assemblies, including Compatibility. Do not add a separate Compatibility package to the consumer. Testing one package alongside the other can hide a missing runtime assembly, so keep the two consumer graphs separate. This startup check does not replace the kernel/storage integration suites below.
Running the Tests
Section titled “Running the Tests”From the command line
Section titled “From the command line”Run the suite with dotnet test from the repository root. --configuration Release matches CI; use Debug for faster local iteration:
dotnet test Integration/Client/Client.csproj \ --logger "console;verbosity=normal" \ --configuration Release \ --framework net11.0 \ -- inprocess mongodbRuntime and database configurations (CLI)
Section titled “Runtime and database configurations (CLI)”The first positional argument after -- is the mode, and the second is the database:
dotnet test Integration/Client/Client.csproj -- outofprocess mongodbdotnet test Integration/Client/Client.csproj -- outofprocess postgresqldotnet test Integration/Client/Client.csproj -- outofprocess mssqldotnet test Integration/Client/Client.csproj -- outofprocess sqlitedotnet test Integration/Client/Client.csproj -- inprocess mongodbNamed arguments are also supported:
dotnet test Integration/Client/Client.csproj -- --mode=outofprocess --database=postgresqldotnet test Integration/Client/Client.csproj -- --mode=inprocess --db=mongodbAlternatively, configure via environment variables or --environment flags:
dotnet test Integration/Client/Client.csproj --environment CHRONICLE_RUNTIME_MODE=inprocessCHRONICLE_RUNTIME_MODE=inprocess dotnet test Integration/Client/Client.csprojFor PostgreSQL and MsSql, set connection details before running tests. The values below are examples only — replace credentials and hosts with values from your local environment:
export CHRONICLE_POSTGRESQL_CONNECTION_DETAILS="Host=localhost;Port=5432;Database=chronicle;Username=postgres;Password=postgres"export CHRONICLE_MSSQL_CONNECTION_DETAILS="Server=localhost,1433;Database=chronicle;User Id=sa;Password=Your_password123;TrustServerCertificate=true"For SQLite, you can optionally set:
export CHRONICLE_SQLITE_CONNECTION_DETAILS="Data Source=/tmp/chronicle.db"SQL Server image pin and startup crashes
Section titled “SQL Server image pin and startup crashes”All SQL Server fixtures, both CI pre-pulls and the local compose service use the explicit SQL Server 2025 CU image in Integration/Client/SqlServerContainerImage.cs. Moving to an older major or CU is not an acceptable startup-flake mitigation. The earlier image-pin workaround was not supported by a bounded repeat-start measurement; the SQL Server 2025 startup failure reported in #4282 is not assumed fixed merely by pinning an image.
When updating the pin, choose a newer CU, update both SQL Server pre-pulls in .github/workflows/integration.yml and the service in Source/Kernel/Server/docker-compose.yml to match, then run python3 .github/scripts/test-sql-server-image-pin.py. CI rejects drifting literals, floating tags and older majors. Confirm the candidate with repeated fresh-container starts and the SQL Server client, storage and clustering shards before landing it.
SQL Server fixtures allow at most three fresh-container startup attempts. Only a fresh Docker inspection showing an exited/dead process, or a ContainerNotRunningException when inspection is unavailable, permits a retry. Readiness timeouts with a still-running process are not retried. Before removal, each crashed attempt captures exit code, OOM/error state and up to 64 log lines / 16 KiB within a ten-second evidence deadline. Retry warnings and the final ContainerStartupFailed include this evidence, so an IsPreemptiveOnEntry() assert remains visible even when a later attempt succeeds. This bounded mitigation does not fix that SQL Server assert.
Running against an external MongoDB
Section titled “Running against an external MongoDB”Set CHRONICLE_MONGODB_CONNECTION_DETAILS to a MongoDB connection string to run Storage.MongoDB.Specs against an external service instead of starting MongoDB containers. The client, kernel, API, MongoDB integration, and clustering suites do not support this external mode.
export CHRONICLE_MONGODB_CONNECTION_DETAILS="mongodb://mongo.example.test:27017/?replicaSet=myReplicaSet"dotnet test Source/Kernel/Storage.MongoDB.Specs/Storage.MongoDB.Specs.csproj --configuration ReleaseUse the service’s connection string unchanged, including authentication, TLS, replica-set, or SRV options. Storage specs create unique, run-prefixed databases and remove only the databases they create. The prefix reduces the available database-name budget by its length. External mode does not start or restart containers or initiate a replica set.
The external service must support the MongoDB features used by the Storage specs, including multi-document transactions and change streams for event-sequence and observation specs. Grant permissions to create and drop databases, create indexes, read/write collections, and enumerate database names. Providing a connection string does not imply compatibility with a managed service; a failing spec can reveal an unsupported feature.
Unset CHRONICLE_MONGODB_CONNECTION_DETAILS to return to the default container-backed Storage spec fixtures. CHRONICLE_SPECS_MONGODB_IMAGE applies only when these fixtures start MongoDB themselves.
Checking a MongoDB-compatible service
Section titled “Checking a MongoDB-compatible service”Use a non-production endpoint you control and set CHRONICLE_MONGODB_CONNECTION_DETAILS to the service’s connection string, as above. Run only the MongoDB storage project:
dotnet test Source/Kernel/Storage.MongoDB.Specs/Storage.MongoDB.Specs.csproj --configuration ReleaseOnly Storage.MongoDB.Specs supports external mode. The service identity needs the database, index, and read/write permissions described above. Record passes and failures per feature rather than treating successful appends as proof of compatibility. Failures caused by missing change-stream or collation support mean the service is unsupported; see storage compatibility for the measured DocumentDB results and startup checks.
The managed Azure DocumentDB service remains unverified. Someone with access must run this check manually against their own endpoint; CI does not test that service. Keep connection strings and credentials out of committed files, logs, and shared results. Unset CHRONICLE_MONGODB_CONNECTION_DETAILS when finished.
Running a single test
Section titled “Running a single test”Use --filter with the fully qualified type name or a substring of it:
dotnet test Integration/Client/Client.csproj \ --filter "FullyQualifiedName~for_EventSequence.when_appending.an_event" \ --no-build \ -- outofprocess mongodbFrom VS Code
Section titled “From VS Code”You can run the same configurations from VS Code by creating a dedicated test launch configuration in .vscode/launch.json:
{ "name": ".NET Test (Client integration - outofprocess mongodb)", "type": "coreclr", "request": "launch", "program": "dotnet", "args": [ "test", "${workspaceFolder}/Integration/Client/Client.csproj", "--framework", "net11.0", "--configuration", "Debug", "--", "outofprocess", "mongodb" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal"}For in-process mode, change the last two arguments to "inprocess" and "mongodb".
For database changes in out-of-process mode, set the second argument to "postgresql", "mssql", or "sqlite".
Per-context storage isolation
Section titled “Per-context storage isolation”The in-process MongoDB lane starts a fresh host for each test context and gives its databases a unique prefix. A previous host can still flush writes after shutdown (#4790); those writes now land in databases that the next context never reads. Context teardown awaits host disposal without wiping its databases in place. The collection fixture drops only the databases belonging to prefixes it issued when the collection ends.
If you use Cratis.Chronicle.XUnit.Integration in your own suite, override ChronicleFixture.UsesPerContextMongoDBHost to return true for an in-process MongoDB fixture. It defaults to false, so package consumers keep the existing shared-host behavior unless they opt in. The prefix is applied by the default MongoDB storage configuration; if your fixture overrides GetStorageConfigurator, pass the fixture’s DatabaseNamePrefix to WithMongoDB as databaseNamePrefix.
Starting and stopping a host per context costs time: measured Projections shards took about 1.8–3.1 times as long as the shared-host baseline. The performance follow-up (#4792) tracks that overhead. Out-of-process and remote-kernel lanes are not covered by this isolation; they still use the kernel reset.
Consecutive runs
Section titled “Consecutive runs”The Integration/Client fixtures publish every container port on a random host port, so consecutive runs — or two runs at once — of that suite do not compete for a port. Docker’s Ryuk reaper removes the containers when a run ends.
The Integration/Api suite, and the reusable out-of-process fixture in Cratis.Chronicle.XUnit.Integration, bind fixed host ports (27018 and 35001). Two of those runs at once collide, and a run started immediately after another can wait for Docker to release the ports.
Test Backups
Section titled “Test Backups”Each test collection automatically takes a MongoDB backup at the end of a run when the backup feature is enabled. Backups are useful for inspecting the state left by a failing test.
Enabling backups
Section titled “Enabling backups”Set the CHRONICLE_BACKUP_ENABLED environment variable to true before running tests:
CHRONICLE_BACKUP_ENABLED=true dotnet test Integration/Client/Client.csproj \ --environment CHRONICLE_RUNTIME_MODE=inprocess \ --environment CHRONICLE_STORAGE_PROVIDER=mongodbWhere backups are stored
Section titled “Where backups are stored”Backups are written to a backups/ directory that sits alongside the compiled test binary. For a Debug build targeting net11.0, that path is:
Integration/Client/bin/Debug/net11.0/backups/The directory is created automatically during fixture initialization — you do not need to create it yourself.
Backup file naming
Section titled “Backup file naming”Each backup file is a gzip-compressed MongoDB archive dump with the following naming pattern:
{prefix}-yyyyMMdd-HHmmss.tgzThe prefix corresponds to the xUnit collection name registered for the test suite. When no prefix is set the timestamp is used alone:
20260412-143025.tgzInspecting a backup
Section titled “Inspecting a backup”Restore a backup to a local mongod instance to inspect the data:
mongorestore --gzip --archive=backups/20260412-143025.tgz