Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test load success percent #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ There are predefined keys for these test.
total-call
total-succeeded
total-lost
success-percent
average-ttl-ms
maximum-ttl-ms
minimum-ttl-ms
Expand Down
8 changes: 8 additions & 0 deletions src/RA.Tests/MockResponseContextWithJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ public void TestLoadForTotalCall()
.Assert("load for total call");
}

[Test]
public void TestLoadForSuccessPercentageCall()
{
_responseWithObject
.TestLoad("load for success average", "success-percent", x => x > 0 && x <= 1)
.Assert("load for success average");
}

[Test]
public void WriteAssertions()
{
Expand Down
1 change: 1 addition & 0 deletions src/RA/Enums/LoadValueTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class LoadValueTypes : Enumeration<LoadValueTypes, string>
public static LoadValueTypes TotalCall = new LoadValueTypes("Total-Call", "Total Call");
public static LoadValueTypes TotalSucceeded = new LoadValueTypes("Total-Succeeded", "Total Succeeded");
public static LoadValueTypes TotalLost = new LoadValueTypes("Total-Lost", "Total Lost");
public static LoadValueTypes SuccessPercent = new LoadValueTypes("Success-Percent", "Success Percent");
public static LoadValueTypes AverageTTLMs = new LoadValueTypes("Average-TTL-Ms", "Average TTL Ms");
public static LoadValueTypes MaximumTTLMs = new LoadValueTypes("Maximum-TTL-Ms", "Maximum TTL Ms");
public static LoadValueTypes MinimumTTLMs = new LoadValueTypes("Minimum-TTL-Ms", "Minimum TTL Ms");
Expand Down
1 change: 1 addition & 0 deletions src/RA/ResponseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ private void ParseLoad()
if (_loadResponses.Any())
{
_loadValues.Add(LoadValueTypes.TotalCall.Value, _loadResponses.Count);
_loadValues.Add(LoadValueTypes.SuccessPercent.Value, _loadResponses.Count(x => x.StatusCode == (int)HttpStatusCode.OK)/_loadResponses.Count);
_loadValues.Add(LoadValueTypes.TotalSucceeded.Value, _loadResponses.Count(x => x.StatusCode == (int)HttpStatusCode.OK));
_loadValues.Add(LoadValueTypes.TotalLost.Value, _loadResponses.Count(x => x.StatusCode == -1));
_loadValues.Add(LoadValueTypes.AverageTTLMs.Value, new TimeSpan((long)_loadResponses.Where(x => x.StatusCode == (int)HttpStatusCode.OK).Average(x => x.Ticks)).TotalMilliseconds);
Expand Down