Repository navigation
Expand file tree
/
Copy pathAppSelfHostTests.cs
More file actions
83 lines (69 loc) · 2.1 KB
/
Copy pathAppSelfHostTests.cs
File metadata and controls
83 lines (69 loc) · 2.1 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Funq;
using NUnit.Framework;
using ServiceStack.Text;
namespace ServiceStack.WebHost.Endpoints.Tests
{
public class SpinWait : IReturn<SpinWait>
{
public int? Iterations { get; set; }
}
public class Sleep : IReturn<Sleep>
{
public int? ForMs { get; set; }
}
public class PerfServices : Service
{
private const int DefaultIterations = 1000 * 1000;
private const int DefaultMs = 100;
public object Any(SpinWait request)
{
Thread.SpinWait(request.Iterations.GetValueOrDefault(DefaultIterations));
return request;
}
public object Any(Sleep request)
{
Thread.Sleep(request.ForMs.GetValueOrDefault(DefaultMs));
return request;
}
}
public class AppHostSmartPool : AppHostHttpListenerSmartPoolBase
{
public AppHostSmartPool() : base("SmartPool Test", typeof(PerfServices).Assembly) { }
public override void Configure(Container container)
{
}
}
[TestFixture]
public class AppSelfHostTests
{
private readonly ServiceStackHost appHost;
public AppSelfHostTests()
{
appHost = new AppHostSmartPool()
.Init()
.Start(Config.ListeningOn);
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
appHost.Dispose();
}
[Test]
public void Can_call_SelfHost_Services()
{
var client = new JsonServiceClient(Config.ServiceStackBaseUri);
client.Get(new Sleep { ForMs = 100 });
client.Get(new SpinWait { Iterations = 1000 });
}
[Test]
public async Task Can_call_SelfHost_Services_async()
{
var client = new JsonServiceClient(Config.ServiceStackBaseUri);
var sleep = await client.GetAsync(new Sleep { ForMs = 100 });
var spin = await client.GetAsync(new SpinWait { Iterations = 1000 });
}
}
}