-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Server not listening after Start() returns (on macOS) #44
Comments
Can you post the full code where you put the Thread.Sleep()? |
I can't post the actual source (proprietary, etc), but here's the essence. It's an xunit test class: using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
namespace Service
{
public class ServiceClientTest : IDisposable
{
private FluentMockServer server;
private MyServiceClient client;
public ServiceClientTest()
{
server = FluentMockServer.Start();
client = new MyServiceClient(server.Urls.Select(u => new Uri(u)).First());
}
public void Dispose()
{
server.Dispose();
client.Dispose();
}
[Fact]
public async Task ClientRequestIsWellFormed()
{
var request = new ServiceRequest() { ... };
server.Given(Request.Create().WithPath("/api/endpoint").UsingPost())
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBodyAsJson(new Dictionary<string, object>
{
["id"] = "requestId",
["analysisId"] = Guid.NewGuid()
}));
// Request fails if we don't sleep here, because the server has not yet finished starting.
Thread.Sleep(100);
var response = await client.SendRequestAsync(request);
Assert.NotNull(response);
}
}
} |
I can confirm that I've had the same issue with WireMock.NET not starting up the server in time on MacOS. |
Are you running on netcore 1.x or 2.0 ? |
@StefH This is on .NET Core 2.0. Adding a 100ms thread sleep works around the issue for us. |
@skunkworks OK. Clear. I was wondering if there is an environment setting to see if I'm running on Linux, Windows or MacOS... I'll investigate this. |
What do you think about returning a Alternately, why not block on the task returned by the inner HTTP server? |
Should be fixed. Download source or use latest NuGet version |
@benjamin-bader and @skunkworks : were you able to test this new source-code / NuGet ? |
We'll give it a shot and report back. Thanks for the fix! |
@StefH looks like this update worked, thanks for the quick fix! |
@skunkworks : I close this issue now, if you have more troubles, create a new issue. |
Hi, I just ported a project from .NET 4.5 to .NET Core 2.0 on macOS. I noticed that a unit test using FluentMockServer started failing with
System.Net.Http.CurlException : Couldn't connect to server
.When I add
Thread.Sleep(100)
after starting the server, the error goes away. I'm assuming that, on macOS at least, the underlying server implementation is a bit more asynchronous than that on .NET proper (or on Mono). I notice thatFluentMockServer.Start(...)
callsStartAsync
on its inner HTTP server. Is there a way to wait for that async start to finish that's more reliable than putting the test thread to sleep?The text was updated successfully, but these errors were encountered: