-
Notifications
You must be signed in to change notification settings - Fork 14
Add SQL connectivity health checks for all database providers #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Aaronontheweb
merged 12 commits into
akkadotnet:dev
from
Aaronontheweb:feature/sql-connectivity-health-checks
Oct 26, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6b1c59c
Implement SQL connectivity health checks for Akka.Persistence
Aaronontheweb 9d37fd7
Simplify SQL connectivity check tests
Aaronontheweb 46cd742
Add SQL connectivity check tests for all database providers
Aaronontheweb ec63b03
Merge branch 'dev' into feature/sql-connectivity-health-checks
Aaronontheweb 03e69cc
Add documentation for customizing health check tags
Aaronontheweb 119a91e
Add connectivity health checks to features documentation
Aaronontheweb e9d4244
Skip Docker-based connectivity check tests on Windows CI
Aaronontheweb 71a5338
Fix xunit test discovery logic for platform-specific test skipping
Aaronontheweb 40d7cf2
Register custom xunit test framework in Hosting.Tests assembly
Aaronontheweb 8c78e88
Enhance platform detection reliability in test framework
Aaronontheweb ad2df4c
Revert SqlFrameworkDiscoverer changes to fix test execution
Aaronontheweb a2f562a
Update to Akka.Hosting 1.5.55-beta1 and use WithCustomHealthCheck API
Aaronontheweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/Akka.Persistence.Sql.Hosting.Tests/MySqlConnectivityCheckSpec.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="MySqlConnectivityCheckSpec.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Akka.Hosting; | ||
| using Akka.Persistence.Sql.Tests.Common.Containers; | ||
| using Akka.Persistence.Sql.Tests.Common.Internal.Xunit; | ||
| using FluentAssertions; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Akka.Persistence.Sql.Hosting.Tests | ||
| { | ||
| [SkipWindows] | ||
| public class MySqlConnectivityCheckSpec : IAsyncLifetime | ||
| { | ||
| private readonly MySqlContainer _container; | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public MySqlConnectivityCheckSpec(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| _container = new MySqlContainer(); | ||
| } | ||
|
|
||
| public async Task InitializeAsync() | ||
| { | ||
| await _container.InitializeAsync(); | ||
| } | ||
|
|
||
| public async Task DisposeAsync() | ||
| { | ||
| await _container.DisposeAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Journal_Connectivity_Check_Should_Return_Healthy_When_Connected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlJournalConnectivityCheck( | ||
| _container.ConnectionString, | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Healthy); | ||
| result.Description.Should().Contain("successful"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Journal_Connectivity_Check_Should_Return_Unhealthy_When_Disconnected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlJournalConnectivityCheck( | ||
| "Server=invalid-host;User=invalid;Password=invalid", | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Unhealthy); | ||
| result.Exception.Should().NotBeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Snapshot_Connectivity_Check_Should_Return_Healthy_When_Connected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlSnapshotStoreConnectivityCheck( | ||
| _container.ConnectionString, | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Healthy); | ||
| result.Description.Should().Contain("successful"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Snapshot_Connectivity_Check_Should_Return_Unhealthy_When_Disconnected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlSnapshotStoreConnectivityCheck( | ||
| "Server=invalid-host;User=invalid;Password=invalid", | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Unhealthy); | ||
| result.Exception.Should().NotBeNull(); | ||
| } | ||
| } | ||
| } |
118 changes: 118 additions & 0 deletions
118
src/Akka.Persistence.Sql.Hosting.Tests/PostgreSqlConnectivityCheckSpec.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="PostgreSqlConnectivityCheckSpec.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Akka.Hosting; | ||
| using Akka.Persistence.Sql.Tests.Common.Containers; | ||
| using Akka.Persistence.Sql.Tests.Common.Internal.Xunit; | ||
| using FluentAssertions; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Akka.Persistence.Sql.Hosting.Tests | ||
| { | ||
| [SkipWindows] | ||
| public class PostgreSqlConnectivityCheckSpec : IAsyncLifetime | ||
| { | ||
| private readonly PostgreSqlContainer _container; | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public PostgreSqlConnectivityCheckSpec(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| _container = new PostgreSqlContainer(); | ||
| } | ||
|
|
||
| public async Task InitializeAsync() | ||
| { | ||
| await _container.InitializeAsync(); | ||
| } | ||
|
|
||
| public async Task DisposeAsync() | ||
| { | ||
| await _container.DisposeAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Journal_Connectivity_Check_Should_Return_Healthy_When_Connected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlJournalConnectivityCheck( | ||
| _container.ConnectionString, | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Healthy); | ||
| result.Description.Should().Contain("successful"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Journal_Connectivity_Check_Should_Return_Unhealthy_When_Disconnected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlJournalConnectivityCheck( | ||
| "Host=invalid-host;Username=invalid;Password=invalid", | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Unhealthy); | ||
| result.Exception.Should().NotBeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Snapshot_Connectivity_Check_Should_Return_Healthy_When_Connected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlSnapshotStoreConnectivityCheck( | ||
| _container.ConnectionString, | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Healthy); | ||
| result.Description.Should().Contain("successful"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Snapshot_Connectivity_Check_Should_Return_Unhealthy_When_Disconnected() | ||
| { | ||
| // Arrange | ||
| var check = new SqlSnapshotStoreConnectivityCheck( | ||
| "Host=invalid-host;Username=invalid;Password=invalid", | ||
| _container.ProviderName, | ||
| "sql"); | ||
|
|
||
| var context = new AkkaHealthCheckContext(null!); | ||
|
|
||
| // Act | ||
| var result = await check.CheckHealthAsync(context, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| result.Status.Should().Be(HealthStatus.Unhealthy); | ||
| result.Exception.Should().NotBeNull(); | ||
| } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/Akka.Persistence.Sql.Hosting.Tests/Properties/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="AssemblyInfo.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| using Xunit; | ||
|
|
||
| [assembly: | ||
| TestFramework( | ||
| "Akka.Persistence.Sql.Tests.Common.Internal.Xunit.SqlTestFramework", | ||
| "Akka.Persistence.Sql.Tests.Common")] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed this to ensure that we use the
SqlFrameworkDiscovererand skip Docker-based integration tests on Windows CI/CD