-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for timers and grouping requests
- Loading branch information
Showing
24 changed files
with
635 additions
and
4 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
25 changes: 25 additions & 0 deletions
25
Abstracta.JmeterDsl.Tests/Core/Controllers/DslSimpleControllerTest.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,25 @@ | ||
namespace Abstracta.JmeterDsl.Core.Controllers | ||
{ | ||
using static JmeterDsl; | ||
|
||
public class DslSimpleControllerTest | ||
{ | ||
[Test] | ||
public void ShouldApplyAssertionToSimpleControllerScopedElements() | ||
{ | ||
var body = "FAIL"; | ||
var stats = TestPlan( | ||
ThreadGroup(1, 1, | ||
SimpleController( | ||
ResponseAssertion() | ||
.ContainsSubstrings("OK"), | ||
DummySampler(body), | ||
DummySampler(body) | ||
), | ||
DummySampler(body) | ||
) | ||
).Run(); | ||
Assert.That(stats.Overall.ErrorsCount, Is.EqualTo(2)); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Abstracta.JmeterDsl.Tests/Core/Controllers/DslTransactionControllerTest.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,20 @@ | ||
namespace Abstracta.JmeterDsl.Core.Controllers | ||
{ | ||
using static JmeterDsl; | ||
|
||
public class DslTransactionControllerTest | ||
{ | ||
[Test] | ||
public void ShouldIncludeTransactionSampleInResultsWhenTestPlanWithTransaction() | ||
{ | ||
TestPlanStats stats = TestPlan( | ||
ThreadGroup(1, 1, | ||
Transaction("My Transaction", | ||
DummySampler("ok") | ||
) | ||
) | ||
).Run(); | ||
Assert.That(stats.Overall.SamplesCount, Is.EqualTo(2)); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Abstracta.JmeterDsl.Tests/Core/Samplers/DslFlowControlActionTest.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,22 @@ | ||
using System; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Samplers | ||
{ | ||
using static JmeterDsl; | ||
|
||
public class DslFlowControlActionTest | ||
{ | ||
[Test] | ||
public void ShouldLastAtLeastConfiguredTimeWhenUsingConstantTimer() | ||
{ | ||
var timerDuration = TimeSpan.FromSeconds(5); | ||
var stats = TestPlan( | ||
ThreadGroup(1, 1, | ||
ThreadPause(timerDuration), | ||
DummySampler("OK") | ||
) | ||
).Run(); | ||
Assert.That(stats.Duration, Is.GreaterThan(timerDuration)); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Abstracta.JmeterDsl.Tests/Core/Timers/DslConstantTimerTest.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,21 @@ | ||
namespace Abstracta.JmeterDsl.Core.Timers | ||
{ | ||
using System; | ||
using static JmeterDsl; | ||
|
||
public class DslConstantTimerTest | ||
{ | ||
[Test] | ||
public void ShouldLastAtLeastConfiguredTimeWhenUsingConstantTimer() | ||
{ | ||
var timerDuration = TimeSpan.FromSeconds(5); | ||
var stats = TestPlan( | ||
ThreadGroup(1, 1, | ||
ConstantTimer(timerDuration), | ||
DummySampler("OK") | ||
) | ||
).Run(); | ||
Assert.That(stats.Duration, Is.GreaterThan(timerDuration)); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Abstracta.JmeterDsl.Tests/Core/Timers/DslUniformRandomTimerTest.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,21 @@ | ||
namespace Abstracta.JmeterDsl.Core.Timers | ||
{ | ||
using System; | ||
using static JmeterDsl; | ||
|
||
public class DslUniformRandomTimerTest | ||
{ | ||
[Test] | ||
public void ShouldLastAtLeastMinimumTimeWhenUsingRandomUniformTimer() | ||
{ | ||
var minimum = TimeSpan.FromSeconds(5); | ||
var stats = TestPlan( | ||
ThreadGroup(1, 1, | ||
UniformRandomTimer(minimum, TimeSpan.FromSeconds(7)), | ||
DummySampler("OK") | ||
) | ||
).Run(); | ||
Assert.That(stats.Duration, Is.GreaterThan(minimum)); | ||
} | ||
} | ||
} |
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,10 @@ | ||
using System; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Bridge | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class YamlTypeAttribute : Attribute | ||
{ | ||
public string TagName { get; set; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Abstracta.JmeterDsl/Core/Controllers/DslSimpleController.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,21 @@ | ||
using Abstracta.JmeterDsl.Core.ThreadGroups; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Controllers | ||
{ | ||
/// <summary> | ||
/// Builds a Simple Controller that allows defining new JMeter scope for other elements to apply. | ||
/// <br/> | ||
/// This is handy for example to apply timers, configs, listeners, assertions, pre- and | ||
/// post-processors to only some samplers in the test plan. | ||
/// <br/> | ||
/// It has a similar functionality as the transaction controller, but it doesn't add any additional | ||
/// sample results (statistics) to the test plan. | ||
/// </summary> | ||
public class DslSimpleController : BaseController<DslSimpleController> | ||
{ | ||
public DslSimpleController(string name, IThreadGroupChild[] children) | ||
: base(name, children) | ||
{ | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Abstracta.JmeterDsl/Core/Controllers/DslTransactionController.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,71 @@ | ||
using Abstracta.JmeterDsl.Core.Bridge; | ||
using Abstracta.JmeterDsl.Core.ThreadGroups; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Controllers | ||
{ | ||
/// <summary> | ||
/// Allows specifying JMeter transaction controllers which group different samples associated to same | ||
/// transaction. | ||
/// <br/> | ||
/// This is usually used when grouping different steps of a flow, for example group requests of login | ||
/// flow, adding item to cart, purchase, etc. It provides aggregate metrics of all it's samples. | ||
/// </summary> | ||
[YamlType(TagName = "transaction")] | ||
public class DslTransactionController : BaseController<DslTransactionController> | ||
{ | ||
private bool _includeTimersAndProcessorsTime; | ||
private bool _generateParentSample; | ||
|
||
public DslTransactionController(string name, IThreadGroupChild[] children) | ||
: base(name, children) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Specifies to include time spent in timers and pre- and post-processors in sample results. | ||
/// </summary> | ||
/// <returns>the controller for further configuration or usage.</returns> | ||
public DslTransactionController IncludeTimersAndProcessorsTime() => | ||
IncludeTimersAndProcessorsTime(true); | ||
|
||
/// <summary> | ||
/// Same as <see cref="IncludeTimersAndProcessorsTime()"/> but allowing to enable or disable it. | ||
/// <br/> | ||
/// This is helpful when the resolution is taken at runtime. | ||
/// </summary> | ||
/// <param name="enable">specifies to enable or disable the setting. By default, it is set to false.</param> | ||
/// <returns>the controller for further configuration or usage.</returns> | ||
/// <seealso cref="IncludeTimersAndProcessorsTime()"/> | ||
public DslTransactionController IncludeTimersAndProcessorsTime(bool enable) | ||
{ | ||
_includeTimersAndProcessorsTime = enable; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Specifies to create a sample result as parent of children samplers. | ||
/// <br/> | ||
/// It is useful in some scenarios to get transaction sample results as parent of children samplers | ||
/// to focus mainly in transactions and not be concerned about each particular request. Enabling | ||
/// parent sampler helps in this regard, only reporting the transactions in summary reports, and | ||
/// not the transaction children results. | ||
/// </summary> | ||
/// <returns>the controller for further configuration or usage.</returns> | ||
public DslTransactionController GenerateParentSample() => | ||
GenerateParentSample(true); | ||
|
||
/// <summary> | ||
/// Same as <see cref="GenerateParentSample()"/> but allowing to enable or disable it. | ||
/// <br/> | ||
/// This is helpful when the resolution is taken at runtime. | ||
/// </summary> | ||
/// <param name="enable">specifies to enable or disable the setting. By default, it is set to false.</param> | ||
/// <returns>the controller for further configuration or usage.</returns> | ||
/// <seealso cref="GenerateParentSample()"/> | ||
public DslTransactionController GenerateParentSample(bool enable) | ||
{ | ||
_generateParentSample = enable; | ||
return this; | ||
} | ||
} | ||
} |
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,22 @@ | ||
using Abstracta.JmeterDsl.Core.Bridge; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Samplers | ||
{ | ||
/// <summary> | ||
/// Uses JMeter Flow Control Action to allow taking different actions (stop, pause, interrupt). | ||
/// </summary> | ||
[YamlType(TagName = "threadPause")] | ||
public class DslFlowControlAction : BaseSampler<DslFlowControlAction> | ||
{ | ||
private readonly string _duration; | ||
|
||
private DslFlowControlAction(string duration) | ||
: base(null) | ||
{ | ||
_duration = duration; | ||
} | ||
|
||
public static DslFlowControlAction PauseThread(string duration) => | ||
new DslFlowControlAction(duration); | ||
} | ||
} |
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,15 @@ | ||
using Abstracta.JmeterDsl.Core.TestElements; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Timers | ||
{ | ||
/// <summary> | ||
/// Contains common logic for all timers. | ||
/// </summary> | ||
public abstract class BaseTimer : BaseTestElement, IMultiLevelTestElement | ||
{ | ||
public BaseTimer(string name) | ||
: base(name) | ||
{ | ||
} | ||
} | ||
} |
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,24 @@ | ||
namespace Abstracta.JmeterDsl.Core.Timers | ||
{ | ||
/// <summary> | ||
/// Allows using JMeter Constant Timers which pause the thread for a given period. | ||
/// <br/> | ||
/// The pause calculated by the timer will be applied after samplers pre-processors execution and | ||
/// before actual sampling. | ||
/// <br/> | ||
/// Take into consideration that timers applies to all samplers in their scope: if added at test plan | ||
/// level, it will apply to all samplers in test plan; if added at thread group level, it will apply | ||
/// only to samples in such thread group; if added as child of a sampler, it will only apply to that | ||
/// sampler. | ||
/// </summary> | ||
public class DslConstantTimer : BaseTimer | ||
{ | ||
private readonly string _duration; | ||
|
||
public DslConstantTimer(string duration) | ||
: base(null) | ||
{ | ||
_duration = duration; | ||
} | ||
} | ||
} |
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,14 @@ | ||
namespace Abstracta.JmeterDsl.Core.Timers | ||
{ | ||
/// <summary> | ||
/// Uses JMeter Synchronizing Timer to allow sending a batch of requests simultaneously to a system | ||
/// under test. | ||
/// </summary> | ||
public class DslSynchronizingTimer : BaseTimer | ||
{ | ||
public DslSynchronizingTimer() | ||
: base(null) | ||
{ | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System; | ||
|
||
namespace Abstracta.JmeterDsl.Core.Timers | ||
{ | ||
/// <summary> | ||
/// Allows specifying JMeter Uniform Random Timers which pause the thread with a random time with | ||
/// uniform distribution. | ||
/// <br/> | ||
/// The pause calculated by the timer will be applied after samplers pre-processors execution and | ||
/// before actual sampling. | ||
/// <br/> | ||
/// Take into consideration that timers applies to all samplers in their scope: if added at test plan | ||
/// level, it will apply to all samplers in test plan; if added at thread group level, it will apply | ||
/// only to samples in such thread group; if added as child of a sampler, it will only apply to that | ||
/// sampler. | ||
/// </summary> | ||
public class DslUniformRandomTimer : BaseTimer | ||
{ | ||
private TimeSpan _minimum; | ||
private TimeSpan _maximum; | ||
|
||
public DslUniformRandomTimer(TimeSpan minimum, TimeSpan maximum) | ||
: base(null) | ||
{ | ||
_minimum = minimum; | ||
_maximum = maximum; | ||
} | ||
} | ||
} |
Oops, something went wrong.