Skip to content

Commit 5f626af

Browse files
committed
added example with ScenarioCompletionTimeout
1 parent fc702e8 commit 5f626af

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

examples/Demo/Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="Bogus" Version="34.0.2" />
3232
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
3333
<PackageReference Include="LiteDB" Version="5.0.15" />
34-
<PackageReference Include="NBomber" Version="5.2.0" />
34+
<PackageReference Include="NBomber" Version="5.2.1" />
3535
<PackageReference Include="NBomber.Data" Version="5.0.0" />
3636
<PackageReference Include="NBomber.Http" Version="5.0.0" />
3737
<PackageReference Include="NBomber.Sinks.InfluxDB" Version="5.0.0" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using NBomber.CSharp;
2+
3+
namespace Demo.Features.Timeouts;
4+
5+
public class ScenarioCompletionTimeout
6+
{
7+
public void Run()
8+
{
9+
// When NBomber finishes load tests, it waits for all running scenarios to complete their tasks.
10+
11+
var scenario = Scenario.Create("scenario_1", async context =>
12+
{
13+
await Task.Delay(8_000); // set 8 sec, but the duration of the scenario is only 1 sec.
14+
return Response.Ok();
15+
})
16+
.WithoutWarmUp()
17+
.WithLoadSimulations(Simulation.KeepConstant(copies: 1, during: TimeSpan.FromSeconds(1))); // set 1 sec duration
18+
19+
var result =
20+
NBomberRunner
21+
.RegisterScenarios(scenario)
22+
.WithScenarioCompletionTimeout(TimeSpan.FromSeconds(10)) // we set 10 sec to wait
23+
.Run();
24+
25+
Console.WriteLine(result.AllOkCount == 1
26+
? "Scenario completed"
27+
: "Scenario not completed"
28+
);
29+
}
30+
}

examples/Demo/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Demo.Features.ElasticsearchLogger;
99
using Demo.Features.RealtimeReporting.CustomReportingSink;
1010
using Demo.Features.RealtimeReporting.InfluxDB;
11+
using Demo.Features.Timeouts;
1112
using Demo.HelloWorld;
1213
using Demo.HelloWorld.LoadSimulation;
1314
using Demo.HTTP;
@@ -18,7 +19,7 @@
1819
// -------------------------------
1920
// -----Hello World examples -----
2021
// -------------------------------
21-
// new HelloWorldExample().Run();
22+
new HelloWorldExample().Run();
2223
// new ScenarioWithInit().Run();
2324
// new ScenarioWithSteps().Run();
2425
// new StepsShareData().Run();
@@ -44,6 +45,9 @@
4445
// new CustomReportingExample().Run();
4546
// new ElasticsearchExample().Run();
4647

48+
// ---- Timeouts ----
49+
// new ScenarioCompletionTimeout().Run();
50+
4751
// ----------------
4852
// ----- HTTP -----
4953
// ----------------
@@ -70,5 +74,5 @@
7074
// ---------------------
7175
// ----- Cluster -------
7276
// ---------------------
73-
new AutoClusterExample().Run();
77+
// new AutoClusterExample().Run();
7478

0 commit comments

Comments
 (0)