Skip to content

Commit

Permalink
fix: Even more robust messaging provider initialisation on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrodger committed Feb 15, 2024
1 parent 8886dec commit 78ec54c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/PactNet/Verifier/Messaging/MessagingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ internal class MessagingProvider : IMessagingProvider
};

private readonly PactVerifierConfig config;
private readonly HttpListener server;
private readonly Thread thread;

private HttpListener server;
private JsonSerializerOptions defaultSettings;

/// <summary>
Expand All @@ -46,7 +46,6 @@ public MessagingProvider(PactVerifierConfig config, IMessageScenarios scenarios)
{
this.config = config;
this.Scenarios = scenarios;
this.server = new HttpListener();
this.thread = new Thread(this.HandleRequest);
}

Expand All @@ -70,6 +69,8 @@ public Uri Start(JsonSerializerOptions settings)
uri = new Uri($"http://localhost:{port}/pact-messages/");

this.config.WriteLine($"Starting messaging provider at {uri}");

this.server = new HttpListener();
this.server.Prefixes.Add(uri.AbsoluteUri);
this.server.Start();
}
Expand Down Expand Up @@ -283,8 +284,8 @@ public void Dispose()

try
{
this.server.Stop();
this.server.Close();
this.server?.Stop();
this.server?.Close();
}
catch
{
Expand Down

0 comments on commit 78ec54c

Please sign in to comment.