-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPerformanceTestingResultTest.cs
72 lines (66 loc) · 2.75 KB
/
PerformanceTestingResultTest.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
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Linq;
using System.Text.RegularExpressions;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using Tests.Support;
using Xunit;
namespace Tests.PerformanceTesting
{
public class PerformanceTestingResultTest
{
private JObject _generalStatistics;
private JObject _applicationPerformanceIndex;
[SkippableFact(DisplayName = "Should have no error in all requests")]
public void TestScenario1()
{
// Arrange
PreparePropertiesAndSkipTestIfNeeded();
// Assert only
_generalStatistics.Count.Should().Be(11);
foreach (var token in _generalStatistics)
{
var errorCount = token.Value["errorCount"].As<int>();
errorCount.Should().Be(0);
}
}
[SkippableFact(DisplayName = "Should APDEX result be greater than 0.9 to all evaluated requests")]
public void TestScenario2()
{
// Arrange
PreparePropertiesAndSkipTestIfNeeded();
var rawOverallResult = _applicationPerformanceIndex["overall"]["data"];
var rawRequestsResults = _applicationPerformanceIndex["items"];
// Assert
rawOverallResult.Should().NotBeNullOrEmpty();
rawRequestsResults.Count().Should().Be(10);
foreach (var token in rawRequestsResults)
{
var apdexResultForGivenRequest = token["data"][0].Value<double>();
apdexResultForGivenRequest.Should().BeGreaterThan(0.9);
}
}
private void PreparePropertiesAndSkipTestIfNeeded()
{
// Skip test if required
var value = Environment.GetEnvironmentVariable("EVALUATE_PERFORMANCE_TESTING");
bool.TryParse(value, out var shouldNotSkipTest);
Skip.If(shouldNotSkipTest is false, "It was informed to be skipped");
// General statistics
_generalStatistics = FileHandler.ReadFileAsDictionary("tests-jmeter/statistics.json");
// APDEX sadly is not in only one file, we should extract it
var lineWhereApdexResultIs = @"createTable($(""#apdexTable"")";
var regexPatternToCaptureResult = @", ({"".+]}), ";
var dashBoardFile = FileHandler.EnumerableFromFile("tests-jmeter/content/js/dashboard.js");
foreach (var line in dashBoardFile)
{
if (line.Contains(lineWhereApdexResultIs))
{
var match = Regex.Match(line, regexPatternToCaptureResult);
var rawApdexResult = match.Groups[1].Value;
_applicationPerformanceIndex = JObject.Parse(rawApdexResult);
}
}
}
}
}