Skip to content

Commit

Permalink
added example with ScenarioCompletionTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Aug 23, 2023
1 parent fc702e8 commit 5f626af
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="LiteDB" Version="5.0.15" />
<PackageReference Include="NBomber" Version="5.2.0" />
<PackageReference Include="NBomber" Version="5.2.1" />
<PackageReference Include="NBomber.Data" Version="5.0.0" />
<PackageReference Include="NBomber.Http" Version="5.0.0" />
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.0" />
Expand Down
30 changes: 30 additions & 0 deletions examples/Demo/Features/Timeouts/ScenarioCompletionTimeout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NBomber.CSharp;

namespace Demo.Features.Timeouts;

public class ScenarioCompletionTimeout
{
public void Run()
{
// When NBomber finishes load tests, it waits for all running scenarios to complete their tasks.

var scenario = Scenario.Create("scenario_1", async context =>
{
await Task.Delay(8_000); // set 8 sec, but the duration of the scenario is only 1 sec.
return Response.Ok();
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(1))); // set 1 sec duration

var result =
NBomberRunner
.RegisterScenarios(scenario)
.WithScenarioCompletionTimeout(TimeSpan.FromSeconds(10)) // we set 10 sec to wait
.Run();

Console.WriteLine(result.AllOkCount == 1
? "Scenario completed"
: "Scenario not completed"
);
}
}
8 changes: 6 additions & 2 deletions examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Demo.Features.ElasticsearchLogger;
using Demo.Features.RealtimeReporting.CustomReportingSink;
using Demo.Features.RealtimeReporting.InfluxDB;
using Demo.Features.Timeouts;
using Demo.HelloWorld;
using Demo.HelloWorld.LoadSimulation;
using Demo.HTTP;
Expand All @@ -18,7 +19,7 @@
// -------------------------------
// -----Hello World examples -----
// -------------------------------
// new HelloWorldExample().Run();
new HelloWorldExample().Run();
// new ScenarioWithInit().Run();
// new ScenarioWithSteps().Run();
// new StepsShareData().Run();
Expand All @@ -44,6 +45,9 @@
// new CustomReportingExample().Run();
// new ElasticsearchExample().Run();

// ---- Timeouts ----
// new ScenarioCompletionTimeout().Run();

// ----------------
// ----- HTTP -----
// ----------------
Expand All @@ -70,5 +74,5 @@
// ---------------------
// ----- Cluster -------
// ---------------------
new AutoClusterExample().Run();
// new AutoClusterExample().Run();

0 comments on commit 5f626af

Please sign in to comment.