|
| 1 | +using NBomber.CSharp; |
| 2 | +using NBomber.Sinks.Timescale; |
| 3 | + |
| 4 | +namespace Demo.NBomber_Studio; |
| 5 | + |
| 6 | +public class NBomberStudioReportingExample |
| 7 | +{ |
| 8 | + // this reporting sink will save stats data into TimescaleDB. |
| 9 | + private readonly TimescaleDbSink _timescaleDbSink = new(); |
| 10 | + |
| 11 | + public void Run() |
| 12 | + { |
| 13 | + var scenario = Scenario.Create("user_flow_scenario", async context => |
| 14 | + { |
| 15 | + var step1 = await Step.Run("login", context, async () => |
| 16 | + { |
| 17 | + await Task.Delay(500); |
| 18 | + return Response.Ok(sizeBytes: 10, statusCode: "200"); |
| 19 | + }); |
| 20 | + |
| 21 | + var step2 = await Step.Run("get_product", context, async () => |
| 22 | + { |
| 23 | + await Task.Delay(1000); |
| 24 | + return Response.Ok(sizeBytes: 20, statusCode: "200"); |
| 25 | + }); |
| 26 | + |
| 27 | + var step3 = await Step.Run("buy_product", context, async () => |
| 28 | + { |
| 29 | + await Task.Delay(2000); |
| 30 | + return Response.Ok(sizeBytes: 30, statusCode: "200"); |
| 31 | + }); |
| 32 | + |
| 33 | + return Response.Ok(statusCode: "201"); |
| 34 | + }) |
| 35 | + .WithWarmUpDuration(TimeSpan.FromSeconds(3)) |
| 36 | + .WithLoadSimulations( |
| 37 | + Simulation.RampingInject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)), // rump-up to rate 200 |
| 38 | + Simulation.Inject(rate: 200, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromSeconds(30)), // keep injecting with rate 200 |
| 39 | + Simulation.RampingInject(rate: 0, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)) // rump-down to rate 0 |
| 40 | + ); |
| 41 | + |
| 42 | + NBomberRunner |
| 43 | + .RegisterScenarios(scenario) |
| 44 | + .LoadInfraConfig("NBomber_Studio/infra-config.json") |
| 45 | + .WithReportingSinks(_timescaleDbSink) |
| 46 | + .WithTestSuite("reporting") |
| 47 | + .WithTestName("timescale_db_demo") |
| 48 | + .Run(); |
| 49 | + } |
| 50 | +} |
0 commit comments