-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCHttpDiffFunctionalTests.cs
More file actions
309 lines (272 loc) · 16.8 KB
/
Copy pathCHttpDiffFunctionalTests.cs
File metadata and controls
309 lines (272 loc) · 16.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
using CHttp.Abstractions;
using CHttp.Data;
using CHttp.Performance.Data;
using CHttp.Performance.Statitics;
using CHttp.Tests.Performance.Statistics;
namespace CHttp.Tests.Performance;
public class CHttpDiffFunctionalTests
{
[Fact]
public async Task DisplayingSingleFile()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
PerformanceMeasurementResults session = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = new[] { new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromSeconds(1)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 } },
Behavior = new(1, 1, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem).Parse($"diff --files session0.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains("| Mean: 1.000 s |", console.Text);
Assert.Contains("| StdDev: 0.000 ns |", console.Text);
Assert.Contains("| Error: 0.000 ns |", console.Text);
Assert.Contains("| Median: 1.000 s |", console.Text);
Assert.Contains("| Min: 1.000 s |", console.Text);
Assert.Contains("| Max: 1.000 s |", console.Text);
Assert.Contains("| 95th: 1.000 s |", console.Text);
Assert.Contains("| Throughput: 100.000 B/s |", console.Text);
Assert.Contains("| Req/Sec: 1 |", console.Text);
Assert.Contains("1xx: 0, 2xx: 1, 3xx: 0, 4xx: 0, 5xx: 0, Other: 0", console.Text);
/* Expect something like this in the output, but actual details depend on the test run.
| Mean: 1.000 s |
| StdDev: 0.000 ns |
| Error: 0.000 ns |
| Median: 1.000 s |
| Min: 1.000 s |
| Max: 1.000 s |
| Throughput: 100.000 B/s |
| Req/Sec: 1 |
--------
HTTP status codes:
1xx: 0, 2xx: 1, 3xx: 0, 4xx: 0, 5xx: 0, Other: 0
--------
*/
}
[Fact]
public async Task DisplayingNoFile()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem).Parse($"diff")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Empty(console.Text);
}
[Fact]
public async Task DisplayingMultipleEqualFile()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
PerformanceMeasurementResults session = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = new[] { new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromSeconds(1)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 } },
Behavior = new(1, 1, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse($"diff --files session0.json --files session0.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains("| Mean: 1.000 s [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| StdDev: 0.000 ns [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Error: 0.000 ns [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Median: 1.000 s [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Min: 1.000 s [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Max: 1.000 s [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| 95th: 1.000 s [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Throughput: 100.000 B/s 0 B/s |", console.Text);
Assert.Contains("| Req/Sec: 1 [color:Green] 0[color:Black] |", console.Text);
Assert.Contains("1xx: 0 +0, 2xx: 1 +0, 3xx: 0 +0, 4xx: 0 +0, 5xx: 0 +0, Other: 0 +0", console.Text);
}
[Fact]
public async Task DisplayingMultipleDifferentFile()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
PerformanceMeasurementResults session0 = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = new[] { new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromSeconds(1)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 } },
Behavior = new(1, 1, false)
};
PerformanceMeasurementResults session1 = new()
{
TotalBytesRead = 400,
MaxConnections = 1,
Summaries = new[] { new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 } },
Behavior = new(1, 1, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session0);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session1.json"), session1);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse($"diff --files session0.json --files session1.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains($"RequestCount: 1, Clients: 1", console.Text);
Assert.Contains("| Mean: 1.000 s [color:Red] +1.000 s [color:Black] |", console.Text);
Assert.Contains("| StdDev: 0.000 ns [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Error: 0.000 ns [color:Green] 0 ns[color:Black] |", console.Text);
Assert.Contains("| Median: 1.000 s [color:Red] +1.000 s [color:Black] |", console.Text);
Assert.Contains("| Min: 1.000 s [color:Red] +1.000 s [color:Black] |", console.Text);
Assert.Contains("| Max: 1.000 s [color:Red] +1.000 s [color:Black] |", console.Text);
Assert.Contains("| 95th: 1.000 s [color:Red] +1.000 s [color:Black] |", console.Text);
Assert.Contains("| Throughput: 100.000 B/s +100.000 B/s |", console.Text);
Assert.Contains("| Req/Sec: 1 [color:Red] -0.5[color:Black] |", console.Text);
Assert.Contains("1xx: 0 +0, 2xx: 1 -1, 3xx: 0 +0, 4xx: 0 +1, 5xx: 0 +0, Other: 0 +0", console.Text);
}
[Fact]
public async Task DisplayingDifferentEndpoints_ShowsWarnings()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
PerformanceMeasurementResults session0 = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = new[] { new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromSeconds(1)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 } },
Behavior = new(1, 1, false)
};
PerformanceMeasurementResults session1 = new()
{
TotalBytesRead = 400,
MaxConnections = 1,
Summaries = new[] { new Summary("different_url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 } },
Behavior = new(1, 1, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session0);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session1.json"), session1);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse($"diff --files session0.json --files session1.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains("*Warning: session files contain different urls: url,different_url", console.Text);
}
[Fact]
public async Task DisplayingDifferent_RequestCount_ShowsWarnings()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
PerformanceMeasurementResults session0 = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = new[] { new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromSeconds(1)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 } },
Behavior = new(1, 1, false)
};
PerformanceMeasurementResults session1 = new()
{
TotalBytesRead = 400,
MaxConnections = 1,
Summaries = new[] {
new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 },
new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 }
},
Behavior = new(2, 1, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session0);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session1.json"), session1);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse($"diff --files session0.json --files session1.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains("*Warning: session files use different test parameters: PerformanceBehavior { RequestCount = 1, ClientsCount = 1, SharedSocketsHandler = False } and PerformanceBehavior { RequestCount = 2, ClientsCount = 1, SharedSocketsHandler = False }", console.Text);
}
[Fact]
public async Task DisplayingDifferent_ClientCount_ShowsWarnings()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
PerformanceMeasurementResults session0 = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = new[] {
new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 },
new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 }
},
Behavior = new(2, 1, false)
};
PerformanceMeasurementResults session1 = new()
{
TotalBytesRead = 400,
MaxConnections = 1,
Summaries = new[] {
new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 },
new Summary("url", new DateTime(2023, 06, 08, 0, 0, 1, DateTimeKind.Utc), TimeSpan.FromSeconds(2)) { ErrorCode = ErrorType.None, HttpStatusCode = 400 }
},
Behavior = new(2, 2, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session0);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session1.json"), session1);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse("diff --files session0.json --files session1.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains($"RequestCount: 2, Clients: 1", console.Text);
Assert.Contains("*Warning: session files use different test parameters: PerformanceBehavior { RequestCount = 2, ClientsCount = 1, SharedSocketsHandler = False } and PerformanceBehavior { RequestCount = 2, ClientsCount = 2, SharedSocketsHandler = False }", console.Text);
}
[Fact]
public async Task DisplayingMultipleHistogram()
{
var console = new TestConsoleAsOuput(windowWidth: 40);
var fileSystem = new MemoryFileSystem();
var summaries0 = new List<Summary>();
for (int i = 0; i < 100; i++)
summaries0.Add(new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromMilliseconds(i)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 });
PerformanceMeasurementResults session0 = new()
{
TotalBytesRead = 100,
MaxConnections = 1,
Summaries = summaries0,
Behavior = new(100, 10, false)
};
var summaries1 = new List<Summary>();
for (int i = 0; i < 100; i++)
summaries1.Add(new Summary("url", new DateTime(2023, 06, 08, 0, 0, 0, DateTimeKind.Utc), TimeSpan.FromMilliseconds(50)) { ErrorCode = ErrorType.None, HttpStatusCode = 200 });
PerformanceMeasurementResults session1 = new()
{
TotalBytesRead = 400,
MaxConnections = 1,
Summaries = summaries1,
Behavior = new(100, 10, false)
};
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session0);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session1.json"), session1);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse($"diff --files session0.json --files session1.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains(" 9.900 ms ##", console.Text);
Assert.Contains(" 19.800 ms ##", console.Text);
Assert.Contains(" 29.700 ms ##", console.Text);
Assert.Contains(" 39.600 ms ##", console.Text);
Assert.Contains(" 49.500 ms ##", console.Text);
Assert.Contains(" 59.400 ms ==++++++++++++++++++", console.Text);
Assert.Contains(" 69.300 ms ##", console.Text);
Assert.Contains(" 79.200 ms ##", console.Text);
Assert.Contains(" 89.100 ms ##", console.Text);
Assert.Contains(" 99.000 ms ##", console.Text);
}
[Fact]
public async Task DisplayBayesianComparison()
{
var console = new TestConsoleAsOuput();
var fileSystem = new MemoryFileSystem();
var (session0, session1) = StatisticsCalculatorTests.GetSessions(100, 110, 1, 5, 100, 100);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session0.json"), session0);
await PerformanceFileHandler.SaveAsync(fileSystem, Path.Join(Environment.CurrentDirectory, "session1.json"), session1);
var client = await CommandFactory.CreateRootCommand(console: console, fileSystem: fileSystem)
.Parse($"diff --files session0.json --files session1.json")
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken)
.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
Assert.Contains("With 100.0% probability, the base session's true mean latency is lower than compared session's.", console.Text);
}
}