mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
Add start delay from 100ms to fix startup issue on MacOS (#44)
This commit is contained in:
@@ -5,8 +5,6 @@ using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WireMock.Http;
|
||||
using WireMock.Validation;
|
||||
|
||||
@@ -18,6 +16,8 @@ namespace WireMock.Owin
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly string[] _uriPrefixes;
|
||||
|
||||
private IWebHost _host;
|
||||
|
||||
public bool IsStarted { get; private set; }
|
||||
|
||||
public List<string> Urls { get; } = new List<string>();
|
||||
@@ -33,9 +33,7 @@ namespace WireMock.Owin
|
||||
{
|
||||
Urls.Add(uriPrefix);
|
||||
|
||||
int port;
|
||||
string host;
|
||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out host, out port);
|
||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
Ports.Add(port);
|
||||
}
|
||||
|
||||
@@ -45,27 +43,26 @@ namespace WireMock.Owin
|
||||
|
||||
public Task StartAsync()
|
||||
{
|
||||
IWebHost host = new WebHostBuilder()
|
||||
// .ConfigureLogging(factory => factory.AddConsole(LogLevel.None))
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseUrls(_uriPrefixes)
|
||||
.Build();
|
||||
_host = new WebHostBuilder()
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseUrls(_uriPrefixes)
|
||||
.Build();
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||
return Task.Run(() =>
|
||||
{
|
||||
host.Run(_cts.Token);
|
||||
_host.Run(_cts.Token);
|
||||
IsStarted = true;
|
||||
}, _cts.Token);
|
||||
#else
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
||||
IsStarted = true;
|
||||
return host.RunAsync(_cts.Token);
|
||||
return _host.RunAsync(_cts.Token);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -74,8 +71,11 @@ namespace WireMock.Owin
|
||||
_cts.Cancel();
|
||||
|
||||
IsStarted = false;
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
return Task.FromResult(true);
|
||||
#else
|
||||
return _host.WaitForShutdownAsync();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user