Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
401 changes: 333 additions & 68 deletions .github/workflows/cloud-database-tests.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ jobs:
uses: ./.github/workflows/build-db-container.yml
secrets: inherit
cloud-tests:
needs: [containers, db-container]
uses: ./.github/workflows/cloud-database-tests.yml
with:
image-tag: ${{ github.ref_name }}
registry: ghcr
secrets: inherit
36 changes: 21 additions & 15 deletions docs/cloud-database-tests.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cloud database tests

The `Cloud database tests` workflow (`.github/workflows/cloud-database-tests.yml`) runs the SQL Server and PostgreSQL persistence and acceptance suites against managed databases. Every target runs nightly on the default branch, and also whenever the release workflow calls it. To run it yourself, start it from the Actions tab and choose one target, or `all`. Starting a run cancels any run of the workflow already in progress on the same branch. The nightly run skips a commit that has already passed a nightly run, and posts to the `pulse-and-control` Slack channel when a target fails or is cancelled. For each target, the `.github/actions/cloud-database` action creates a server for the run, exports the connection strings below, and deletes the server when the job ends.
The `Cloud database tests` workflow (`.github/workflows/cloud-database-tests.yml`) runs the [container smoke tests](../tools/testing-tool/TestingTool.ContainerSmokeTests/README.md) against managed and local databases. It runs every night at 03:17 UTC on the default branch using the `latest` image tag from Docker Hub. Manual and reusable calls require an `image-tag` input. The plan rejects a missing, empty, or whitespace-only tag for those calls, then trims it and checks that it is a valid container image tag. The optional `registry` input selects `docker` (Docker Hub, `docker.io/particular`, the default) or `ghcr` (`ghcr.io/particular`), and the plan rejects any other value. Starting a run cancels any run of the workflow already in progress on the same branch. Scheduled failures notify the `pulse-and-control` Slack channel; manual and release runs do not. For each managed target, the `.github/actions/cloud-database` action creates a server for the run, exports the connection strings below, and deletes the server when the job ends.

| Variable | Targets | Signs in with |
| --- | --- | --- |
Expand All @@ -9,28 +9,34 @@ The `Cloud database tests` workflow (`.github/workflows/cloud-database-tests.yml
| `ServiceControl_Persistence_SqlServer_TokenConnectionString` | `azure-sqlserver` | A Microsoft Entra ID token |
| `ServiceControl_Persistence_PostgreSql_TokenConnectionString` | `azure-postgresql`, `aurora-postgresql` | A Microsoft Entra ID token on Azure, an IAM token on Aurora |

## Schema cleanup
The smoke scenarios use only the password connection strings. The token connection strings are for the [token authentication fixtures](testing-persistence.md#token-authentication-fixtures) in the persistence test projects, which this workflow does not run.

The cloud workflow sets `ServiceControl_TESTS_SKIP_SCHEMA_CLEANUP=true` on its test step. SQL Server and PostgreSQL test helpers leave each test's schema in place, avoiding schema-drop timeouts. Tests still use unique schemas and retain host shutdown, connection disposal, and temporary-file cleanup. The provisioning action deletes the server in its post step, including on test failure or cancellation.
## Container smoke tests

When schema cleanup is disabled, SQL Server cleanup disables each completed test's full-text indexes after its host stops. This stops unfinished populations and automatic updates without dropping tables or schemas, so retained indexes do not keep indexing for later tests. Cleanup uses a separate connection because host disposal can dispose the test's data source. PostgreSQL cleanup remains a no-op.
The release workflow waits for the application images and the RavenDB database image, then passes the release tag as `image-tag` with `registry: ghcr`, because release images exist only in GHCR at that point. A manual run can supply any image tag published to the selected registry, for example `7.0.3`, and can select one database target or `all`. Every run selects the scenarios below, or the scenarios for the selected target.

Disabling an index still executes DDL and can encounter lock contention. This does not remove contention from concurrent schema creation or migrations, or guarantee that a live test's full-text population completes. See [ALTER FULLTEXT INDEX](https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-fulltext-index-transact-sql#arguments) for the effects of `DISABLE`.
Each smoke scenario has separate `transport`, `storage`, and `bodystorage` values, and its name joins those values with hyphens. The explicit list covers the testing tool's supported transports, persistence providers, and available body stores without testing every combination. Managed resources use same-cloud combinations where possible; repeated transports use local containers. Azure SQL and RDS SQL Server are the SQL Server storage targets. SQL Server storage requires full-text search, which the local SQL Server container does not provide. The SQL Server container serves only as a transport and needs no full-text search. The storage of that scenario is the PostgreSQL container. The tool does not support Azure Storage Queues, IBM MQ, or MSMQ, so those CI transport categories are outside this smoke-test list.

Schema cleanup remains enabled when the variable is unset or has any value other than `true` (case-insensitive). Set it only for disposable databases whose owner deletes the database after the run. Retained tables and indexes consume storage until deletion.
| Transport | Storage | Body storage |
| --- | --- | --- |
| Azure Service Bus | Azure SQL Server | Azure Blob |
| RabbitMQ | Azure PostgreSQL | File system |
| Amazon SQS | Aurora PostgreSQL | File system |
| RabbitMQ | RDS SQL Server | File system |
| SQL Server container | PostgreSQL container | File system |
| PostgreSQL container | PostgreSQL container | File system |
| RabbitMQ | RavenDB container | RavenDB attachments |

## Token authentication fixtures
Conditional installer steps provision each dependency. The SQL Server, PostgreSQL, RabbitMQ, Azure Service Bus, and Azure storage-account installers are also used by CI. The single `Run container smoke tests` step then builds the settings file and per-instance body settings from the scenario's transport, storage, and body storage, and ends with `dotnet test --logger GitHubActions`, which reports results as annotations and in the job summary. Local services expose a Docker bridge address that both the runner and the ServiceControl containers can reach. The plan maps the registry once, and the workflow logs in to the selected registry with the Docker Hub credentials or the `GITHUB_TOKEN`. It passes the registry path to the tests as `SC_CONTAINER_TESTS_REGISTRY`. The RavenDB container uses `servicecontrol-ravendb` from the same registry path, with the same tag as the application images. It keeps the image's default server URL, the container's private address, and allows unsecured access from private networks. An unsecured RavenDB server whose URL falls outside the allowed range, such as `0.0.0.0`, answers every request with 503.

The suites use the password connection strings. Only the token authentication fixtures use the token connection strings, and each fixture is ignored when its variable is not set. A token fixture applies the migrations to a new schema, writes a row and reads it back, all through the token login. It drops the schema through that login unless schema cleanup is disabled.
File system bodies use separate primary and audit directories. Azure Blob bodies use separate containers in the account created by the Azure storage installer. RavenDB stores bodies internally and receives no external body-storage settings.

* `azure-sqlserver` makes the service principal that `azure/login` signed in as the server's Microsoft Entra admin and keeps SQL authentication enabled. The connection string has `Authentication=Active Directory Default` and no `User ID` or `Password`. SqlClient gets the token from `DefaultAzureCredential`, which finds the Azure CLI sign-in on the runner.
* `azure-postgresql` enables Microsoft Entra authentication alongside password authentication and makes the same service principal a Microsoft Entra admin of the server. The admin's role name is the principal's client ID. The connection string uses that client ID as its `Username` and sets `Token Authentication=AzureEntraId`.
* `aurora-postgresql` enables IAM database authentication on the cluster and creates an `sc_iam` user that has `rds_iam` and `CREATE` on the test database. The master user must not get `rds_iam`: a user with that role can no longer sign in with a password, and the suites sign in as the master user. The connection string sets `Token Authentication=AwsRdsIam`.
The S3 scenario, a SQL Server transport with PostgreSQL container storage, is commented out because the repository has no S3 bucket installer with cleanup. It does not provide active S3 coverage. Enabling it requires bucket provisioning and cleanup, S3 settings for each instance, and inclusion in the plan's body-storage allowlist.

## AWS permissions
The Amazon SQS scenario uses the `AWS_REGION` secret and the `GHA-<run id>` queue prefix from `ci.yml`. It applies the same prefix to SNS topics for run isolation. The smoke-test step overrides its process's region; database provisioning and post-step teardown retain `AWS_DATABASE_REGION`.

The AWS identity that the workflow uses needs `rds-db:connect` for `sc_iam`. The file `.github/actions/cloud-database/aws-iam-policy.json` lists every permission that identity needs, this one included. The workflow does not apply the file, so add a new permission to the identity by hand before the first run that depends on it.
The workflow delegates queue deletion to the [Amazon SQS cleanup workflow](https://github.com/Particular/NServiceBus.AmazonSQS/blob/master/.github/workflows/tests-cleanup.yml). That job must target the same AWS account and region; this repository does not verify its secrets. It does not delete SNS topics. The plan warns that the scenario leaves its prefixed topics behind.

## Running a token fixture locally
## AWS permissions

Set the fixture's variable to a connection string for a server that accepts your own token login. For example, use a server where you are the Microsoft Entra admin and have signed in with `az login`.
The file `.github/actions/cloud-database/aws-iam-policy.json` documents AWS database permissions, including `rds-db:connect` for the optional `sc_iam` token fixtures. The workflow does not apply this policy. Configure the database permissions and the [SQS transport permissions](https://docs.particular.net/transports/sqs/) on the AWS identity before running the corresponding scenario.
24 changes: 23 additions & 1 deletion docs/testing-persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All persistence test projects can be run with `dotnet test` against the correspo

## Test isolation on the SQL persisters

The SQL Server and PostgreSQL suites give each test its own **schema** in one shared database, named `sc_test_<guid>` for persistence tests and `sc_at_<guid>` for acceptance tests, and drop it on teardown. This uses the same `Database/Schema` setting that is offered to customers, so every run exercises that feature.
The SQL Server and PostgreSQL suites give each test its own **schema** in one shared database, named `sc_test_<guid>` for persistence tests and `sc_at_<guid>` for acceptance tests, and drop it on teardown by default. This uses the same `Database/Schema` setting that is offered to customers, so every run exercises that feature.

Two consequences follow:

Expand Down Expand Up @@ -45,3 +45,25 @@ ServiceControl_Persistence_PostgreSql_ConnectionString
```

to a valid PostgreSQL connection string. It must name a database that exists, because the tests create their schemas in whatever database it points at. The test container creates a `servicecontroltests` database for this, so that test schemas do not end up in the `postgres` maintenance database.

## Schema cleanup

Setting `ServiceControl_TESTS_SKIP_SCHEMA_CLEANUP=true` makes the SQL Server and PostgreSQL test helpers leave each test's schema in place, avoiding schema-drop timeouts. Tests still use unique schemas and retain host shutdown, connection disposal, and temporary-file cleanup.

When schema cleanup is disabled, SQL Server cleanup disables each completed test's full-text indexes after its host stops. This stops unfinished populations and automatic updates without dropping tables or schemas, so retained indexes do not keep indexing for later tests. Cleanup uses a separate connection because host disposal can dispose the test's data source. PostgreSQL cleanup remains a no-op.

Disabling an index still executes DDL and can encounter lock contention. This does not remove contention from concurrent schema creation or migrations, or guarantee that a live test's full-text population completes. See [ALTER FULLTEXT INDEX](https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-fulltext-index-transact-sql#arguments) for the effects of `DISABLE`.

Schema cleanup remains enabled when the variable is unset or has any value other than `true` (case-insensitive). Set it only for disposable databases whose owner deletes the database after the run. Retained tables and indexes consume storage until deletion.

## Token authentication fixtures

The persistence suites use the password connection strings. Only the token authentication fixtures use the token connection strings, and each fixture is ignored when its variable is not set. The [cloud database tests](cloud-database-tests.md) provisioner exports the token connection strings for its managed targets, but its container smoke scenarios do not run these fixtures. A token fixture applies the migrations to a new schema, writes a row and reads it back, all through the token login. It drops the schema through that login unless schema cleanup is disabled.

* `azure-sqlserver` makes the service principal that `azure/login` signed in as the server's Microsoft Entra admin and keeps SQL authentication enabled. The connection string has `Authentication=Active Directory Default` and no `User ID` or `Password`. SqlClient gets the token from `DefaultAzureCredential`, which finds the Azure CLI sign-in on the runner.
* `azure-postgresql` enables Microsoft Entra authentication alongside password authentication and makes the same service principal a Microsoft Entra admin of the server. The admin's role name is the principal's client ID. The connection string uses that client ID as its `Username` and sets `Token Authentication=AzureEntraId`.
* `aurora-postgresql` enables IAM database authentication on the cluster and creates an `sc_iam` user that has `rds_iam` and `CREATE` on the test database. The master user must not get `rds_iam`: a user with that role can no longer sign in with a password, and the suites sign in as the master user. The connection string sets `Token Authentication=AwsRdsIam`.

## Running a token fixture locally

Set the fixture's variable to a connection string for a server that accepts your own token login. For example, use a server where you are the Microsoft Entra admin and have signed in with `az login`.
4 changes: 2 additions & 2 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ On Windows, [PackagedRavenDBTests](../src/ServiceControlInstaller.Engine.UnitTes

## Persistence tests

Persistence tests check assumptions at the persistence seam level by exercising each persister. For local setup details, see [Local testing of persistence providers](testing-persistence.md). For the workflow that runs these suites against managed cloud databases, see [Cloud database tests](cloud-database-tests.md).
Persistence tests check assumptions at the persistence seam level by exercising each persister. For local setup details, see [Local testing of persistence providers](testing-persistence.md). For the workflow that smoke tests container images against managed and local databases, see [Cloud database tests](cloud-database-tests.md).

The RavenDB persistence test projects contain an `IndexDefinitionTests` test that approves the definition of every index the persister deploys. The test first deploys the indexes to a new database with the Lucene settings that `DatabaseSetup` uses, so the approved text is the definition a new installation deploys. The indexes inherit Lucene from that database, so a `Configuration` line in the approved file comes from the index definition itself. RavenDB rebuilds an index side by side when its definition changes, and the rebuild of a large database can take days. When the test fails, record the changed indexes in the upgrade guide of the next release before you approve the new definition. An operator who locked an index must unlock it to receive the change. See [Database schema and index changes](guidelines/database-schema-and-index-changes.md) for when such a change can ship.

Expand Down Expand Up @@ -117,7 +117,7 @@ Containers built by a PR and stored on GitHub Container Registry can be tested l

## Container tests with the testing tool

The [container tests](../tools/testing-tool/TestingTool.ContainerSmokeTests/README.md) start the ServiceControl, audit and monitoring containers from an image tag and run the testing tool's smoke checks against them, using a transport, database and cloud resources that you provide. They run only when `SC_CONTAINER_TESTS_TAG` is set, so a normal test run never starts a container. The README covers the prerequisites, the settings and examples with PostgreSQL and with Amazon SQS and S3.
The [container tests](../tools/testing-tool/TestingTool.ContainerSmokeTests/README.md) start the ServiceControl, audit and monitoring containers from an image tag and run the testing tool's smoke checks against them, using a transport, database and cloud resources that you provide. They run only when `SC_CONTAINER_TESTS_TAG` is set, so a normal test run never starts a container. The README covers the prerequisites, the settings and examples with PostgreSQL and with Amazon SQS and S3. The [cloud database workflow](cloud-database-tests.md#container-smoke-tests) provisions dependencies for an explicit list of transport, storage, and body-storage scenarios. It uses Docker Hub images by default, can use GHCR, and requires an image tag except on its scheduled `latest` run.

## Smoke tests with the testing tool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Migrates_round_trips_locks_and_drops_the_schema_with_a_real_to

if (string.IsNullOrEmpty(connectionString))
{
Assert.Ignore($"{TokenConnectionStrings.CloudVariable} is not set. The cloud database tests set it for the azure-postgresql and aurora-postgresql targets, see docs/cloud-database-tests.md.");
Assert.Ignore($"{TokenConnectionStrings.CloudVariable} is not set. See docs/testing-persistence.md#token-authentication-fixtures.");
}

var schema = $"sc_token_{Guid.NewGuid():n}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task Migrates_round_trips_and_drops_the_schema_with_a_real_token()

if (string.IsNullOrEmpty(connectionString))
{
Assert.Ignore($"{TokenConnectionStrings.CloudVariable} is not set. The cloud database tests set it for the azure-postgresql and aurora-postgresql targets, see docs/cloud-database-tests.md.");
Assert.Ignore($"{TokenConnectionStrings.CloudVariable} is not set. See docs/testing-persistence.md#token-authentication-fixtures.");
}

var settings = TokenAuthenticationTests.CreateSettings(connectionString, $"sc_token_{Guid.NewGuid():n}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void RequireTokenConnectionString()

if (string.IsNullOrEmpty(connectionString))
{
Assert.Ignore($"{ConnectionStringVariable} is not set. The cloud database tests set it for the azure-sqlserver target, see docs/cloud-database-tests.md.");
Assert.Ignore($"{ConnectionStringVariable} is not set. See docs/testing-persistence.md#token-authentication-fixtures.");
}
}

Expand Down
Loading
Loading