-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"GlobalSettings": { | ||
"ScenariosSettings": [ | ||
{ | ||
"ScenarioName": "http_scenario", | ||
|
||
"LoadSimulationsSettings": [ | ||
{ "Inject": [1, "00:00:01", "00:00:30"] } | ||
], | ||
|
||
"ThresholdSettings": [ | ||
|
||
{ "OkRequest": "RPS >= 30" }, | ||
{ "OkRequest": "Percent > 90" }, | ||
|
||
{ "FailRequest": "Percent < 10" }, | ||
|
||
{ "OkLatency": "max < 100" }, | ||
{ "OkLatency": "p75 < 80" }, | ||
|
||
{ "OkDataTransfer": "p75 < 80" }, | ||
|
||
{ "StatusCode": ["500", "Percent < 5"] }, | ||
{ "StatusCode": ["400", "Percent < 10"], "AbortWhenErrorCount": 5 }, | ||
{ "StatusCode": ["200", "Percent >= 50"], "AbortWhenErrorCount": 5, "StartCheckAfter": "00:00:10" } | ||
|
||
] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using NBomber.Contracts; | ||
using NBomber.CSharp; | ||
using NBomber.Http.CSharp; | ||
using Xunit; | ||
|
||
namespace xUnitExample; | ||
|
||
public class Thresholds | ||
{ | ||
[Fact] | ||
public void Runtime_Thresholds_Example() | ||
{ | ||
using var httpClient = new HttpClient(); | ||
|
||
var scenario = Scenario.Create("http_scenario", async context => | ||
{ | ||
var step1 = await Step.Run("step_1", context, async () => | ||
{ | ||
var request = | ||
Http.CreateRequest("GET", "https://nbomber.com") | ||
.WithHeader("Content-Type", "application/json"); | ||
|
||
var response = await Http.Send(httpClient, request); | ||
|
||
return response; | ||
}); | ||
|
||
return Response.Ok(); | ||
}) | ||
.WithoutWarmUp() | ||
.WithLoadSimulations(Simulation.Inject(rate: 1, interval: TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30))) | ||
.WithThresholds( | ||
// Scenario's threshold that checks: error rate < 10% | ||
Threshold.Create(scenarioStats => scenarioStats.Fail.Request.Percent < 10), | ||
|
||
// Step's threshold that checks: error rate < 10% | ||
Threshold.Create("step_1", stepStats => stepStats.Fail.Request.Percent < 10), | ||
|
||
// Scenario's threshold that checks if any response contains status code 404 | ||
Threshold.Create( | ||
scenarioStats => scenarioStats.Fail.StatusCodes.Exists("404"), | ||
|
||
abortWhenErrorCount: 5, // Threshold checks are executed based on the ReportingInterval (by default each 5 sec), | ||
// so when the threshold ErrorCount = 5, the load test will be aborted. | ||
// By default, 'abortWhenErrorCount' is null meaning Thresholds errors will not abort the test execution. | ||
|
||
|
||
startCheckAfter: TimeSpan.FromSeconds(10) // Threshold check will be delayed on 10 sec | ||
), | ||
|
||
Threshold.Create(scenarioStats => scenarioStats.Ok.StatusCodes.Find("200")?.Percent >= 80) | ||
); | ||
|
||
var result = NBomberRunner | ||
.RegisterScenarios(scenario) | ||
.Run(); | ||
|
||
// Here, we attempt to find a failed threshold, and if one is found (i.e., it is not null), we throw an exception. | ||
var failedThreshold = result.Thresholds.FirstOrDefault(x => x.IsFailed); | ||
|
||
Assert.True(failedThreshold == null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using NBomber.CSharp; | ||
using NBomber.Http.CSharp; | ||
using Xunit; | ||
|
||
namespace xUnitExample; | ||
|
||
public class ThresholdsFromConfig | ||
{ | ||
[Fact] | ||
public void Runtime_Thresholds_Example() | ||
{ | ||
using var httpClient = new HttpClient(); | ||
|
||
var scenario = Scenario.Create("http_scenario", async context => | ||
{ | ||
var step1 = await Step.Run("step_1", context, async () => | ||
{ | ||
var request = | ||
Http.CreateRequest("GET", "https://nbomber.com") | ||
.WithHeader("Content-Type", "application/json"); | ||
|
||
var response = await Http.Send(httpClient, request); | ||
|
||
return response; | ||
}); | ||
|
||
return Response.Ok(); | ||
}) | ||
.WithoutWarmUp() | ||
.WithLoadSimulations( | ||
Simulation.Inject(rate: 1, interval: TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30)) | ||
); | ||
|
||
var result = NBomberRunner | ||
.RegisterScenarios(scenario) | ||
.LoadConfig("Configs/nbomber-config.json") | ||
.Run(); | ||
|
||
// Here, we attempt to find a failed threshold, and if one is found (i.e., it is not null), we throw an exception. | ||
var failedThreshold = result.Thresholds.FirstOrDefault(x => x.IsFailed); | ||
|
||
Assert.True(failedThreshold != null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters