Skip to content
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

Migrate HealthChecks.Milvus tests to Testcontainers #2360

Merged
merged 2 commits into from
Jan 9, 2025
Merged
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
45 changes: 5 additions & 40 deletions .github/workflows/healthchecks_milvus_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'wget'
run: 'wget https://github.com/milvus-io/milvus/releases/download/v2.4.6/milvus-standalone-docker-compose.yml -O docker-compose.yml'
- name: 'compose'
run: 'sudo docker compose up -d'
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore
run: |
dotnet restore ./src/HealthChecks.Milvus/HealthChecks.Milvus.csproj &&
dotnet restore ./test/HealthChecks.Milvus.Tests/HealthChecks.Milvus.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Milvus/HealthChecks.Milvus.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Milvus.Tests/HealthChecks.Milvus.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Milvus/HealthChecks.Milvus.csproj &&
dotnet build --no-restore ./test/HealthChecks.Milvus.Tests/HealthChecks.Milvus.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.Milvus.Tests/HealthChecks.Milvus.Tests.csproj
--no-restore
--no-build
--collect "XPlat Code Coverage"
--results-directory .coverage
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: Upload Coverage
uses: codecov/codecov-action@v5
with:
flags: Milvus
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.Milvus/HealthChecks.Milvus.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.Milvus.Tests/HealthChecks.Milvus.Tests.csproj
CODECOV_FLAGS: Milvus
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="TestContainers.MongoDb" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.MsSql" Version="$(TestcontainersVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using System.Net;
using Aspire.Milvus.Client.Tests;
using Milvus.Client;

namespace HealthChecks.Milvus.Tests.Functional;

public class milvus_healthcheck_should
public class milvus_healthcheck_should(MilvusContainerFixture milvusContainerFixture) : IClassFixture<MilvusContainerFixture>
{
[Fact]
public async Task be_healthy_when_milvus_is_available_using_client_factory()
{
string connectionString = milvusContainerFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services
.AddHealthChecks()
.AddMilvus(
clientFactory: sp => new MilvusClient("localhost"), tags: new string[] { "milvus" });
clientFactory: sp => new MilvusClient(new Uri(connectionString)), tags: new string[] { "milvus" });
})
.Configure(app =>
{
Expand All @@ -34,11 +37,13 @@ public async Task be_healthy_when_milvus_is_available_using_client_factory()
[Fact]
public async Task be_healthy_when_milvus_is_available_using_singleton()
{
string connectionString = milvusContainerFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services
.AddSingleton(new MilvusClient("localhost"))
.AddSingleton(new MilvusClient(new Uri(connectionString)))
.AddHealthChecks()
.AddMilvus(tags: new string[] { "milvus" });
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Testcontainers.Milvus" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\HealthChecks.Milvus\HealthChecks.Milvus.csproj" />
</ItemGroup>
Expand Down
37 changes: 37 additions & 0 deletions test/HealthChecks.Milvus.Tests/MilvusContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Testcontainers.Milvus;

namespace Aspire.Milvus.Client.Tests;

public sealed class MilvusContainerFixture : IAsyncLifetime
{
public const string Registry = "docker.io";

public const string Image = "milvusdb/milvus";

public const string Tag = "v2.4.13";

public MilvusContainer? Container { get; private set; }

public string GetConnectionString() => Container?.GetEndpoint().AbsoluteUri ??
throw new InvalidOperationException("The test container was not initialized.");

public async Task InitializeAsync() => Container = await CreateContainerAsync();

public async Task DisposeAsync()
{
if (Container is not null)
{
await Container.DisposeAsync();
}
}

public static async Task<MilvusContainer> CreateContainerAsync()
{
var container = new MilvusBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.Build();
await container.StartAsync();

return container;
}
}
Loading