mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 13:00:33 +01:00
[PR #1375] [MERGED] Add WireMockHealthCheck in WireMock.Net.Aspire #1366
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/wiremock/WireMock.Net/pull/1375
Author: @Zguy
Created: 11/5/2025
Status: ✅ Merged
Merged: 11/17/2025
Merged by: @StefH
Base:
master← Head:aspire_healthcheck📝 Commits (3)
2c4d484Add WireMockHealthCheckc1a05d9Move WireMockMappingState to its own file505f0a4Dispose the cancellation tokens in WireMockServerLifecycleHook📊 Changes
8 files changed (+104 additions, -16 deletions)
View changed files
📝
examples-Aspire/AspireApp1.AppHost/Program.cs(+2 -1)➕
src/WireMock.Net.Aspire/WireMockHealthCheck.cs(+44 -0)➕
src/WireMock.Net.Aspire/WireMockMappingState.cs(+10 -0)📝
src/WireMock.Net.Aspire/WireMockServerBuilderExtensions.cs(+12 -0)📝
src/WireMock.Net.Aspire/WireMockServerLifecycleHook.cs(+29 -14)📝
src/WireMock.Net.Aspire/WireMockServerResource.cs(+4 -0)📝
test/WireMock.Net.Aspire.Tests/IntegrationTests.cs(+2 -0)📝
test/WireMock.Net.Aspire.Tests/WireMockServerBuilderExtensionsTests.cs(+1 -1)📄 Description
I know the contributing guidelines says to make an issue first to have a discussion, but we can have the discussion here and I don't mind if the effort was wasted.
The point of this change is to make
WaitFor()in Aspire more useful with WireMock, since it currently doesn't wait for anything. This can be a problem and create a race condition if the main project starts doing HTTP calls to the wiremock server immediately on startup, and will on some runs get a 404 back.To fix that I've added a health check that calls
/__admin/healthand checks the result, as well as checks if mappings using AdminApiMappingBuilder has been submitted to the server.That last part 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.
Submitter checklist
#help-contributingor a project-specific channel like#wiremock-java🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.