In my Specflow project i have a .features file with multiple test scenarios. the thing those tests have in common is that they all use a single Wiremock Server.
Now when I run the tests they always fail except for one. This problem also occurs when i deactivate parallel running in Ncrunch or VS testrunner.
I have tried running a single test while ignoring all the others, the test always passes so I came up with the conclusion that something is wrong with my wiremock server. Is there a special configuration needed for Wiremock server when running multiple scenarios in one .features file?
This is part of the specflow Hook File that sets up the tests:
public static void RegisterServices(ScenarioContext scenarioContext)
{
WireMockServer httpBackend = RegisterWireMock(scenarioContext);
// ...
scenarioContext.Set(httpBackend);
}
private static WireMockServer RegisterWireMock(ScenarioContext scenarioContext)
{
var httpBackend = WireMockServer.Start(new WireMockServerSettings()
{
UseSSL = false
});
scenarioContext.ScenarioContainer.RegisterInstanceAs(httpBackend, dispose: true);
return httpBackend;
}
[BeforeScenario]
public static void Setup(ScenarioContext scenarioContext)
{
RegisterServices(scenarioContext);
/// ...
var httpBackend = scenarioContext.Get<WireMockServer>();
// Setup expectations for wiremock server ...
}
[AfterScenario]
public static void DisposeAll(ScenarioContext context)
{
/// ...
context.Get<WireMockServer>().Dispose();
}
// In this method, which is called during all integration tests,
// the tests fail because of a timeout. The timeout occurs because of
// the manual reset event never being set what should happen if the log
// entries of our wiremock server change. (and this works if you run the
// tests manually, one-by-one).
private void WaitForMessage(Predicate<ILogEntry> selector = null)
{
var httpBackend = context.Get<WireMockServer>();
using CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
using ManualResetEventSlim waitHandle = new ManualResetEventSlim();
httpBackend.LogEntriesChanged += (object sender, NotifyCollectionChangedEventArgs e) =>
{
if (selector == null)
{
waitHandle.Set(); // <----
return;
}
/// ...
foreach (ILogEntry item in e.NewItems)
{
if (selector(item))
{
waitHandle.Set(); // <----
return;
}
}
};
waitHandle.Wait(cts.Token); // <---- TIMEOUT EXCEPTION LEADING TO FAILED TEST
cts.Token.ThrowIfCancellationRequested();
}
Wiremock Server Settings:
11/9/2021 9:38:17 AM [Debug] : WireMock.Net server settings {
"Port": null,
"UseSSL": false,
"StartAdminInterface": null,
"ReadStaticMappings": null,
"WatchStaticMappings": null,
"WatchStaticMappingsInSubdirectories": null,
"ProxyAndRecordSettings": null,
"Urls": null,
"StartTimeout": 10000,
"AllowPartialMapping": null,
"AdminUsername": null,
"AdminPassword": null,
"RequestLogExpirationDuration": null,
"MaxRequestLogCount": null,
"AllowCSharpCodeMatcher": null,
"AllowBodyForAllHttpMethods": null,
"AllowOnlyDefinedHttpStatusCodeInResponse": null,
"DisableJsonBodyParsing": null,
"DisableRequestBodyDecompressing": null,
"HandleRequestsSynchronously": true,
"ThrowExceptionWhenMatcherFails": null,
"CertificateSettings": null,
"CustomCertificateDefined": false,
"WebhookSettings": null
}