[PR #1375] [MERGED] Add WireMockHealthCheck in WireMock.Net.Aspire #1366

Closed
opened 2025-12-29 16:19:57 +01:00 by adam · 0 comments
Owner

📋 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: masterHead: aspire_healthcheck


📝 Commits (3)

  • 2c4d484 Add WireMockHealthCheck
  • c1a05d9 Move WireMockMappingState to its own file
  • 505f0a4 Dispose 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/health and 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

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/wiremock/WireMock.Net/pull/1375 **Author:** [@Zguy](https://github.com/Zguy) **Created:** 11/5/2025 **Status:** ✅ Merged **Merged:** 11/17/2025 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `aspire_healthcheck` --- ### 📝 Commits (3) - [`2c4d484`](https://github.com/wiremock/WireMock.Net/commit/2c4d484a131613be83f6a9e274af200b1c54684d) Add WireMockHealthCheck - [`c1a05d9`](https://github.com/wiremock/WireMock.Net/commit/c1a05d9f519e221aa33ab3ce3d21ba069ce95640) Move WireMockMappingState to its own file - [`505f0a4`](https://github.com/wiremock/WireMock.Net/commit/505f0a4767875fdc98d780a6b3b3270345313336) Dispose the cancellation tokens in WireMockServerLifecycleHook ### 📊 Changes **8 files changed** (+104 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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/health` and 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. <!-- Please describe your pull request here. --> ## Submitter checklist - [ ] Recommended: Join [WireMock Slack](https://slack.wiremock.org/) to get any help in `#help-contributing` or a project-specific channel like `#wiremock-java` - [x] The PR request is well described and justified, including the body and the references - [x] The PR title represents the desired changelog entry - [x] The repository's code style is followed (see the contributing guide) - [x] Test coverage that demonstrates that the change works as expected - [ ] For new features, there's necessary documentation in this pull request or in a subsequent PR to [wiremock.org](https://github.com/wiremock/wiremock.org) <!-- Put an `x` into the [ ] to show you have filled the information. The template comes from https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md You can override it by creating .github/pull_request_template.md in your own repository --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 16:19:57 +01:00
adam closed this issue 2025-12-29 16:19:57 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#1366