This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SequentialTests.cs
59 lines (52 loc) · 1.85 KB
/
SequentialTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Amp;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace Amp.Tests
{
class SequencingWarmUp : IWarmUp
{
static int _master = 0;
public int Sequence { get; private set; }
public Task InvokeAsync()
{
Sequence = ++_master;
return Task.CompletedTask;
}
}
public class SequentialTests : IntegrationTest
{
[Fact]
public Task ShouldExecuteWarmUpsSequentially() =>
TestAsync(async client =>
{
await client.GetAsync("/warmup");
string json = await client.GetStringAsync("/");
var numbers = JsonConvert.DeserializeObject<int[]>(json);
Assert.Equal(100, numbers.Length);
Assert.Equal(Enumerable.Range(1, 100), numbers);
});
protected override void Configure(IApplicationBuilder app)
=> app.UseWarmUp();
protected override void ConfigureServices(IServiceCollection services)
=> Enumerable.Range(0, 100)
.Aggregate(services, (svc, _) => svc.AddSingleton<IWarmUp, SequencingWarmUp>())
.AddWarmUp(options => options.Parallelism = WarmUpParallelism.Sequential);
protected override void Run(IApplicationBuilder app)
{
app.Run(async ctx =>
{
var sequences = ctx.RequestServices
.GetServices<IWarmUp>()
.OfType<SequencingWarmUp>()
.Select(x => x.Sequence);
string json = JsonConvert.SerializeObject(sequences);
await ctx.Response.WriteAsync(json);
});
}
}
}