mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-07-06 04:45:13 +02:00
Add start delay from 100ms to fix startup issue on MacOS (#44)
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>netcoreapp1.1;netcoreapp2.0</TargetFrameworks>
|
<TargetFrameworks>netcoreapp2.0;netcoreapp1.1</TargetFrameworks>
|
||||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace WireMock.Net.StandAlone
|
namespace WireMock.Net.StandAlone.Net452
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
<ProjectGuid>{668F689E-57B4-422E-8846-C0FF643CA999}</ProjectGuid>
|
<ProjectGuid>{668F689E-57B4-422E-8846-C0FF643CA999}</ProjectGuid>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>WireMock.Net.StandAlone</RootNamespace>
|
<RootNamespace>WireMock.Net.StandAlone.Net452</RootNamespace>
|
||||||
<AssemblyName>WireMock.Net.StandAlone</AssemblyName>
|
<AssemblyName>WireMock.Net.StandAlone.Net452</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
@@ -35,38 +35,15 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>..\..\WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>..\..\WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject>WireMock.Net.StandAlone.Net452.Program</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Handlebars, Version=1.8.1.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\Handlebars.Net.1.9.0\lib\net40\Handlebars.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.3.1.0\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="RestEase, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\RestEase.1.4.1\lib\net45\RestEase.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="SimMetrics.Net, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.3\lib\net45\SimMetrics.Net.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Numerics" />
|
<Reference Include="System.Numerics" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="WireMock.Net, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\..\src\WireMock.Net.StandAlone\bin\$(Configuration)\net452\WireMock.Net.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="WireMock.Net.StandAlone, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\..\src\WireMock.Net.StandAlone\bin\$(Configuration)\net452\WireMock.Net.StandAlone.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="XPath2, Version=1.0.3.1, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\XPath2.1.0.3.1\lib\net452\XPath2.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
@@ -75,6 +52,16 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj">
|
||||||
|
<Project>{b6269aac-170a-43d5-8b9a-579ded3d9a95}</Project>
|
||||||
|
<Name>WireMock.Net.StandAlone</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj">
|
||||||
|
<Project>{d3804228-91f4-4502-9595-39584e5a01ad}</Project>
|
||||||
|
<Name>WireMock.Net</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Handlebars.Net" version="1.9.0" targetFramework="net452" />
|
|
||||||
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
|
||||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
|
||||||
<package id="RestEase" version="1.4.1" targetFramework="net452" />
|
|
||||||
<package id="SimMetrics.Net" version="1.0.3" targetFramework="net452" />
|
|
||||||
<package id="XPath2" version="1.0.3.1" targetFramework="net452" />
|
|
||||||
</packages>
|
</packages>
|
||||||
@@ -5,8 +5,6 @@ using System.Threading.Tasks;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
@@ -18,6 +16,8 @@ namespace WireMock.Owin
|
|||||||
private readonly WireMockMiddlewareOptions _options;
|
private readonly WireMockMiddlewareOptions _options;
|
||||||
private readonly string[] _uriPrefixes;
|
private readonly string[] _uriPrefixes;
|
||||||
|
|
||||||
|
private IWebHost _host;
|
||||||
|
|
||||||
public bool IsStarted { get; private set; }
|
public bool IsStarted { get; private set; }
|
||||||
|
|
||||||
public List<string> Urls { get; } = new List<string>();
|
public List<string> Urls { get; } = new List<string>();
|
||||||
@@ -33,9 +33,7 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
Urls.Add(uriPrefix);
|
Urls.Add(uriPrefix);
|
||||||
|
|
||||||
int port;
|
PortUtil.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||||
string host;
|
|
||||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out host, out port);
|
|
||||||
Ports.Add(port);
|
Ports.Add(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,27 +43,26 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
public Task StartAsync()
|
public Task StartAsync()
|
||||||
{
|
{
|
||||||
IWebHost host = new WebHostBuilder()
|
_host = new WebHostBuilder()
|
||||||
// .ConfigureLogging(factory => factory.AddConsole(LogLevel.None))
|
.Configure(appBuilder =>
|
||||||
.Configure(appBuilder =>
|
{
|
||||||
{
|
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
})
|
||||||
})
|
.UseKestrel()
|
||||||
.UseKestrel()
|
.UseUrls(_uriPrefixes)
|
||||||
.UseUrls(_uriPrefixes)
|
.Build();
|
||||||
.Build();
|
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_3
|
||||||
System.Console.WriteLine("WireMock.Net server using netstandard1.3");
|
System.Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
host.Run(_cts.Token);
|
_host.Run(_cts.Token);
|
||||||
IsStarted = true;
|
IsStarted = true;
|
||||||
}, _cts.Token);
|
}, _cts.Token);
|
||||||
#else
|
#else
|
||||||
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
||||||
IsStarted = true;
|
IsStarted = true;
|
||||||
return host.RunAsync(_cts.Token);
|
return _host.RunAsync(_cts.Token);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +71,11 @@ namespace WireMock.Owin
|
|||||||
_cts.Cancel();
|
_cts.Cancel();
|
||||||
|
|
||||||
IsStarted = false;
|
IsStarted = false;
|
||||||
|
#if NETSTANDARD1_3
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
|
#else
|
||||||
|
return _host.WaitForShutdownAsync();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
@@ -20,6 +21,7 @@ namespace WireMock.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class FluentMockServer : IDisposable
|
public partial class FluentMockServer : IDisposable
|
||||||
{
|
{
|
||||||
|
private const int ServerStartDelay = 100;
|
||||||
private readonly IOwinSelfHost _httpServer;
|
private readonly IOwinSelfHost _httpServer;
|
||||||
private readonly object _syncRoot = new object();
|
private readonly object _syncRoot = new object();
|
||||||
private readonly WireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
private readonly WireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||||
@@ -173,6 +175,9 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
_httpServer.StartAsync();
|
_httpServer.StartAsync();
|
||||||
|
|
||||||
|
// Fix for 'Bug: Server not listening after Start() returns (on macOS)'
|
||||||
|
Task.Delay(ServerStartDelay).Wait();
|
||||||
|
|
||||||
if (settings.AllowPartialMapping == true)
|
if (settings.AllowPartialMapping == true)
|
||||||
{
|
{
|
||||||
AllowPartialMapping();
|
AllowPartialMapping();
|
||||||
@@ -318,7 +323,10 @@ namespace WireMock.Server
|
|||||||
Check.NotNull(password, nameof(password));
|
Check.NotNull(password, nameof(password));
|
||||||
|
|
||||||
string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
|
string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
|
||||||
_options.AuthorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$");
|
lock (_syncRoot)
|
||||||
|
{
|
||||||
|
_options.AuthorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -327,7 +335,10 @@ namespace WireMock.Server
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void RemoveBasicAuthentication()
|
public void RemoveBasicAuthentication()
|
||||||
{
|
{
|
||||||
_options.AuthorizationMatcher = null;
|
lock (_syncRoot)
|
||||||
|
{
|
||||||
|
_options.AuthorizationMatcher = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -337,7 +348,10 @@ namespace WireMock.Server
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void SetMaxRequestLogCount([CanBeNull] int? maxRequestLogCount)
|
public void SetMaxRequestLogCount([CanBeNull] int? maxRequestLogCount)
|
||||||
{
|
{
|
||||||
_options.MaxRequestLogCount = maxRequestLogCount;
|
lock (_syncRoot)
|
||||||
|
{
|
||||||
|
_options.MaxRequestLogCount = maxRequestLogCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -347,7 +361,10 @@ namespace WireMock.Server
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void SetRequestLogExpirationDuration([CanBeNull] int? requestLogExpirationDuration)
|
public void SetRequestLogExpirationDuration([CanBeNull] int? requestLogExpirationDuration)
|
||||||
{
|
{
|
||||||
_options.RequestLogExpirationDuration = requestLogExpirationDuration;
|
lock (_syncRoot)
|
||||||
|
{
|
||||||
|
_options.RequestLogExpirationDuration = requestLogExpirationDuration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user