mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-20 08:13:53 +01:00
Fix issue with concurrent logging (#63)
* Fix issue with concurrent logging * Fix namespace + code format/cleanup
This commit is contained in:
committed by
Stef Heyenrath
parent
6c38400827
commit
a15e6747b0
@@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
@@ -8,7 +13,7 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class ObservableLogEntriesTest: IDisposable
|
||||
public class ObservableLogEntriesTest : IDisposable
|
||||
{
|
||||
private FluentMockServer _server;
|
||||
|
||||
@@ -35,6 +40,42 @@ namespace WireMock.Net.Tests
|
||||
Check.That(count).Equals(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ParallelTest()
|
||||
{
|
||||
var expectedCount = 100;
|
||||
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Request.Create()
|
||||
.WithPath("/foo")
|
||||
.UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithDelay(6)
|
||||
.WithSuccess());
|
||||
|
||||
int count = 0;
|
||||
_server.LogEntriesChanged += (sender, args) => count++;
|
||||
|
||||
var http = new HttpClient();
|
||||
|
||||
// Act
|
||||
var listOfTasks = new List<Task<HttpResponseMessage>>();
|
||||
for (var i = 0; i < expectedCount; i++)
|
||||
{
|
||||
Thread.Sleep(3);
|
||||
listOfTasks.Add(http.GetAsync(_server.Urls[0] + $"/foo"));
|
||||
}
|
||||
var responses = await Task.WhenAll(listOfTasks);
|
||||
var countResponsesWithStatusNotOk = responses.Where(r => r.StatusCode != HttpStatusCode.OK).Count();
|
||||
|
||||
// Assert
|
||||
Check.That(countResponsesWithStatusNotOk).Equals(0);
|
||||
Check.That(count).Equals(expectedCount);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_server?.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user