Implement Random Delay (#633)

* implement random delays

* fixing CodeFactor issue

* fix code comments

* ...

* UT

Co-authored-by: Michael Yarichuk <michael.yarichuk@gmail.com>
This commit is contained in:
Stef Heyenrath
2021-09-22 13:37:41 +02:00
committed by GitHub
parent c67bf75a4b
commit ba0b9d9fd8
7 changed files with 169 additions and 11 deletions

View File

@@ -115,6 +115,38 @@ namespace WireMock.Net.Tests
server.Stop();
}
[Fact]
public async Task WireMockServer_Should_randomly_delay_responses_for_a_given_route()
{
// Arrange
var server = WireMockServer.Start();
server
.Given(Request.Create()
.WithPath("/*"))
.RespondWith(Response.Create()
.WithBody(@"{ msg: ""Hello world!""}")
.WithRandomDelay(10, 1000));
var watch = new Stopwatch();
watch.Start();
var httClient = new HttpClient();
async Task<long> ExecuteTimedRequestAsync()
{
watch.Reset();
await httClient.GetStringAsync("http://localhost:" + server.Ports[0] + "/foo");
return watch.ElapsedMilliseconds;
}
// Act
await ExecuteTimedRequestAsync();
await ExecuteTimedRequestAsync();
await ExecuteTimedRequestAsync();
server.Stop();
}
[Fact]
public async Task WireMockServer_Should_delay_responses()
{