Add WireMockHealthCheck in WireMock.Net.Aspire (#1375)

* Add WireMockHealthCheck

For use with Aspire, to make WaitFor(wiremock) more useful.
Calls /__admin/health and checks the result, as well as checks if mappings using AdminApiMappingBuilder has been submitted to the server.

This created a catch-22 problem where the mappings were not submitted until the health check was healthy, but the health check was not healthy until the mappings were submitted.

To avoid this, the WireMockServerLifecycleHook class has been slightly re-arranged, and is now using the AfterEndpointsAllocatedAsync callback rather than the AfterResourcesCreatedAsync callback. Within which a separate Task is created that waits until the server is ready and submits the mappings.

* Move WireMockMappingState to its own file

* Dispose the cancellation tokens in WireMockServerLifecycleHook
This commit is contained in:
Johannes Häggqvist
2025-11-17 20:14:42 +01:00
committed by GitHub
parent 21601889e0
commit 8e69f36f04
8 changed files with 104 additions and 16 deletions

View File

@@ -19,6 +19,7 @@ public class IntegrationTests(ITestOutputHelper output)
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
await using var app = await appHostBuilder.BuildAsync();
await app.StartAsync();
await app.ResourceNotifications.WaitForResourceHealthyAsync("wiremock-service");
using var httpClient = app.CreateHttpClient("wiremock-service");
@@ -46,6 +47,7 @@ public class IntegrationTests(ITestOutputHelper output)
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
await using var app = await appHostBuilder.BuildAsync();
await app.StartAsync();
await app.ResourceNotifications.WaitForResourceHealthyAsync("wiremock-service");
var adminClient = app.CreateWireMockAdminClient("wiremock-service");

View File

@@ -67,7 +67,7 @@ public class WireMockServerBuilderExtensionsTests
MappingsPath = null,
HttpPort = port
});
wiremock.Resource.Annotations.Should().HaveCount(5);
wiremock.Resource.Annotations.Should().HaveCount(6);
var containerImageAnnotation = wiremock.Resource.Annotations.OfType<ContainerImageAnnotation>().FirstOrDefault();
containerImageAnnotation.Should().BeEquivalentTo(new ContainerImageAnnotation