mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-11-21 16:01:38 +01:00
Add near-miss diagnostics and request count/unmatched endpoints to the admin API (#1521)
* Add near-miss diagnostics and request count/unmatched admin endpoints (#171) Add IWireMockServer.FindUnmatchedLogEntries, FindNearMisses and FindNearMissesForUnmatchedRequests, which rank the mappings that partially match a request by score. Expose them through the admin API (POST requests/count, GET requests/unmatched, GET requests/unmatched/near-misses and GET requests/{guid}/near-misses), the RestClient and the OpenAPI document. * Make scenario delay tests independent of server warm-up time The two *_StateTransitions_BeforeDelayCompletes tests waited a fixed 100 ms for the scenario state to change, which fails on a cold server. Poll server.Scenarios until the expected state is reached instead. --------- Co-authored-by: Mattias <13809209+Quattordici@users.noreply.github.com>
This commit is contained in:
1 parent
c94824bd64
commit
dc14136492
18 files changed
+1104
-62
No files matched your search
@@ -442,8 +442,9 @@ public class StatefulBehaviorTests
|
||||
// Act: fire request 1 but don't await it yet — it will sit in a 500 ms delay
|
||||
var request1Task = client.GetStringAsync(server.Url + path, cancellationToken);
|
||||
|
||||
// Give the server a moment to match & transition state before the delay completes
|
||||
await Task.Delay(100, cancellationToken);
|
||||
// Wait until the server has matched request 1 & transitioned the state; request 1 must still be delayed
|
||||
await WaitForScenarioStateAsync(server, "1260", "State1", cancellationToken);
|
||||
request1Task.IsCompleted.Should().BeFalse();
|
||||
|
||||
// Request 2 is sent while request 1 is still being delayed.
|
||||
// After the fix the state has already transitioned, so request 2 matches Mapping 2.
|
||||
@@ -481,7 +482,8 @@ public class StatefulBehaviorTests
|
||||
|
||||
// Act
|
||||
var request1Task = client.GetStringAsync(server.Url + path, cancellationToken);
|
||||
await Task.Delay(100, cancellationToken);
|
||||
await WaitForScenarioStateAsync(server, "s", "State1", cancellationToken);
|
||||
request1Task.IsCompleted.Should().BeFalse();
|
||||
var response2 = await client.GetStringAsync(server.Url + path, cancellationToken);
|
||||
var response1 = await request1Task;
|
||||
|
||||
@@ -574,5 +576,20 @@ public class StatefulBehaviorTests
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Polls the scenario state instead of using a fixed delay, so tests do not depend on how fast the server handles the first request
|
||||
/// (a cold server can take longer than a fixed delay to match the request and transition the state).
|
||||
/// </summary>
|
||||
private static async Task WaitForScenarioStateAsync(WireMockServer server, string scenario, string expectedState, CancellationToken cancellationToken)
|
||||
{
|
||||
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||
timeout.CancelAfter(TimeSpan.FromSeconds(5));
|
||||
|
||||
while (server.Scenarios.FirstOrDefault(s => s.Name == scenario)?.NextState != expectedState)
|
||||
{
|
||||
await Task.Delay(10, timeout.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user