diff --git a/README.md b/README.md index e95e4a4..6160dcc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/RA.Tests/MockResponseContextWithJson.cs b/src/RA.Tests/MockResponseContextWithJson.cs index c00eb8c..905f63a 100644 --- a/src/RA.Tests/MockResponseContextWithJson.cs +++ b/src/RA.Tests/MockResponseContextWithJson.cs @@ -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() { diff --git a/src/RA/Enums/LoadValueTypes.cs b/src/RA/Enums/LoadValueTypes.cs index 675c705..877d572 100644 --- a/src/RA/Enums/LoadValueTypes.cs +++ b/src/RA/Enums/LoadValueTypes.cs @@ -7,6 +7,7 @@ public class LoadValueTypes : Enumeration 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"); diff --git a/src/RA/ResponseContext.cs b/src/RA/ResponseContext.cs index 183743b..873b15c 100644 --- a/src/RA/ResponseContext.cs +++ b/src/RA/ResponseContext.cs @@ -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);