-
Notifications
You must be signed in to change notification settings - Fork 130
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
38 changed files
with
300 additions
and
1,160 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
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 was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
examples/CSharpDev/CustomReporting/CustomReportingExample.cs
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,60 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Serilog; | ||
|
||
using NBomber.Configuration; | ||
using NBomber.Contracts; | ||
using NBomber.Contracts.Stats; | ||
using NBomber.CSharp; | ||
using static NBomber.Time; | ||
|
||
namespace CSharpDev.CustomReporting; | ||
|
||
class CustomReportingSink : IReportingSink | ||
{ | ||
private ILogger _logger; | ||
public string SinkName => nameof(CustomReportingSink); | ||
|
||
public Task Init(IBaseContext context, IConfiguration infraConfig) | ||
{ | ||
_logger = context.Logger; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task Start() => Task.CompletedTask; | ||
public Task SaveRealtimeStats(ScenarioStats[] stats) => Task.CompletedTask; | ||
public Task SaveFinalStats(NodeStats[] stats) => Task.CompletedTask; | ||
public Task Stop() => Task.CompletedTask; | ||
|
||
public void Dispose() | ||
{ } | ||
} | ||
|
||
public class CustomReportingExample | ||
{ | ||
public static void Run() | ||
{ | ||
var step = Step.Create("step", async context => | ||
{ | ||
await Task.Delay(Seconds(0.1)); | ||
return Response.Ok(sizeBytes: 100); | ||
}); | ||
|
||
var scenario = ScenarioBuilder | ||
.CreateScenario("simple_scenario", step) | ||
.WithoutWarmUp() | ||
.WithLoadSimulations(Simulation.KeepConstant(1, TimeSpan.FromMinutes(1))); | ||
|
||
NBomberRunner | ||
.RegisterScenarios(scenario) | ||
.WithTestSuite("reporting") | ||
.WithTestName("custom_reporting_test") | ||
.WithReportingSinks(new CustomReportingSink()) | ||
.WithReportingInterval(Seconds(10)) | ||
.WithReportFolder("./custom_reports") | ||
.WithReportFormats(ReportFormat.Html, ReportFormat.Md, ReportFormat.Txt, ReportFormat.Csv) | ||
.Run(); | ||
} | ||
} |
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,57 @@ | ||
namespace CSharpDev.Features; | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using NBomber.Contracts; | ||
using NBomber.CSharp; | ||
|
||
public class CustomScenarioSettings | ||
{ | ||
public int TestField { get; set; } | ||
public int PauseMs { get; set; } | ||
} | ||
|
||
public class CustomSettingsExample | ||
{ | ||
static CustomScenarioSettings _customSettings = new CustomScenarioSettings(); | ||
|
||
static Task ScenarioInit(IScenarioContext context) | ||
{ | ||
_customSettings = context.CustomSettings.Get<CustomScenarioSettings>(); | ||
|
||
context.Logger.Information( | ||
"test init received CustomSettings.TestField '{TestField}'", | ||
_customSettings.TestField | ||
); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public static void Run() | ||
{ | ||
var step = Step.Create("step", async context => | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(0.1)); | ||
|
||
context.Logger.Debug( | ||
"step received CustomSettings.TestField '{TestField}'", | ||
_customSettings.TestField | ||
); | ||
|
||
return Response.Ok(); // this value will be passed as response for the next step | ||
}); | ||
|
||
var customPause = Step.CreatePause(() => _customSettings.PauseMs); | ||
|
||
var scenario = ScenarioBuilder | ||
.CreateScenario("my_scenario", step, customPause) | ||
.WithInit(ScenarioInit); | ||
|
||
NBomberRunner | ||
.RegisterScenarios(scenario) | ||
.LoadConfig("./Features/config.json") | ||
.Run(); | ||
} | ||
} | ||
|
7 changes: 3 additions & 4 deletions
7
...elloWorld/CustomStepExecControlExample.cs → .../Features/CustomStepExecControlExample.cs
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.