Skip to content

Commit

Permalink
improved InitDBScenario for LiteDb
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Feb 13, 2023
1 parent 3bfd820 commit 98f2fd5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
using Microsoft.Extensions.Configuration;
using NBomber.Contracts;
using NBomber.CSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyLoadTest
namespace CSharpProd.DB.LiteDB
{
public class LiteDBCustomSettings
{
Expand Down Expand Up @@ -101,6 +96,7 @@ public ScenarioProps Create()
})
.WithClean(context =>
{
_db.Checkpoint();
_db.Dispose();
return Task.CompletedTask;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using Bogus;
using LiteDB;
using MyLoadTest;
using NBomber.CSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpProd.Db.LiteDB
namespace CSharpProd.DB.LiteDB
{
public class LiteDBExample
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

namespace MyLoadTest
namespace CSharpProd.DB.LiteDB
{
public enum Gender
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Microsoft.Extensions.Configuration;
using NBomber.Contracts;
using NBomber.Contracts.Stats;
using NBomber.CSharp;

namespace CSharpProd.Features.CustomSettings;

public class CustomScenarioSettings
{
public int TestField { get; set; }
public int PauseMs { get; set; }
public int MyTestField { get; set; }
public int MyPauseMs { get; set; }
}

public class CustomSettingsExample
Expand All @@ -19,8 +20,8 @@ Task Init(IScenarioInitContext initContext)
_customSettings = initContext.CustomSettings.Get<CustomScenarioSettings>();

initContext.Logger.Information(
"test init received CustomSettings.TestField '{TestField}'",
_customSettings.TestField
"test init received CustomSettings.MyTestField '{0}'",
_customSettings.MyTestField
);

return Task.CompletedTask;
Expand All @@ -30,23 +31,33 @@ public void Run()
{
var scenario = Scenario.Create("my_scenario", async context =>
{
await Task.Delay(_customSettings.PauseMs);
await Task.Delay(_customSettings.MyPauseMs);
var step = await Step.Run("step", context, async () =>
{
await Task.Delay(1_000);
context.Logger.Debug("step received CustomSettings.TestField '{0}'", _customSettings.TestField);
context.Logger.Debug("step received CustomSettings.MyTestField '{0}'", _customSettings.MyTestField);
return Response.Ok();
});
return Response.Ok();
})
.WithInit(Init)
.WithoutWarmUp();
.WithLoadSimulations(Simulation.Inject(rate: 50, interval: TimeSpan.FromSeconds(1), during: TimeSpan.FromMinutes(1)))
.WithWarmUpDuration(TimeSpan.FromSeconds(10))
.WithMaxFailCount(1_000);

NBomberRunner
.RegisterScenarios(scenario)
.LoadConfig("./Features/CustomSettings/config.json")
.WithTestSuite("my test suite")
.WithTestName("my test name")
.WithTargetScenarios("my_scenario")
.WithReportFileName("my_report")
.WithReportFolder("report_folder")
.WithReportFormats(ReportFormat.Txt, ReportFormat.Html)
.WithReportingInterval(TimeSpan.FromSeconds(10))
.EnableHintsAnalyzer(true)
.Run();
}
}
Expand Down
16 changes: 10 additions & 6 deletions examples/CSharpProd/Features/CustomSettings/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
],

"CustomSettings": {
"TestField": 1,
"PauseMs": 200
}
"MyTestField": 1,
"MyPauseMs": 200
},

"MaxFailCount": 500
}
],

"ReportFileName": "my_report_name",
"ReportFolder": "./reports",
"ReportFormats": [ "Html", "Md", "Txt", "Csv" ]
"ReportFileName": "my_custom_report_name",
"ReportFolder": "./my_reports",
"ReportFormats": ["Html", "Txt"],
"ReportingInterval": "00:00:30",
"EnableHintsAnalyzer": false
}
}
2 changes: 1 addition & 1 deletion examples/CSharpProd/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CSharpProd.Db.LiteDB;
using CSharpProd.DB.LiteDB;
using CSharpProd.Features;
using CSharpProd.Features.CliArgs;
using CSharpProd.Features.CustomSettings;
Expand Down

0 comments on commit 98f2fd5

Please sign in to comment.