Skip to content

Commit be50737

Browse files
committed
merged
2 parents 4438be6 + 6a2c329 commit be50737

File tree

11 files changed

+406
-195
lines changed

11 files changed

+406
-195
lines changed

.github/workflows/sonarqube-analysis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v2
1313
with:
14-
# Disabling shallow clone is recommended for improving relevancy of reporting
1514
fetch-depth: 0
1615
- name: Setup .NET Core 3.1
1716
uses: actions/setup-dotnet@v1

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.3.0</Version>
3+
<Version>0.3.1</Version>
44
</PropertyGroup>
55
</Project>

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var content = File.ReadAllText("Assets/getPetById.json");
2626
var httpRequest = JsonConvert.DeserializeObject<IEnumerable<HttpRequest>>(content);
2727

2828
//Create bombardier tests generator
29-
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
29+
var bombardierTestsGenerator = new BombardierTestsGenerator(httpRequest, options =>
3030
{
3131
options.BombardierConcurrentUsers = 1;
3232
options.BombardierDuration = 1;
@@ -35,7 +35,7 @@ var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
3535
});
3636

3737
//Generate bomardier tests
38-
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
38+
var bombardierTests = await bombardierTestsGenerator.Generate();
3939

4040
//Run Bombardier Tests
4141
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(), options =>
@@ -105,7 +105,7 @@ var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
105105

106106
You can also set those `BombardierGeneratorOptions` options:
107107

108-
- `BombardierConcurrentUsers`: How many concurrent users should be used in Bombardier tests. Default is `3`.
108+
- `BombardierConcurrentUsers`: How many concurrent users should be used in Bombardier tests. Default is `10`.
109109
- `BombardierDuration`: How long the Bombardier tests should execute in seconds. Use this depending on the type of test you want to perform and should not be used with `BombardierRateLimit`. Default is `30` seconds.
110110
- `BombardierTimeout`: What is the Bombardier timeout to wait for the requests to finish. Default is `30` seconds.
111111
- `BombardierUseHttp2`: Use HTTP2 protocol. Otherwise HTTP1 is used. By default this is set to `true`.

src/QAToolKit.Engine.Bombardier.Test/BombardierTestsGeneratorTests.cs

Lines changed: 328 additions & 133 deletions
Large diffs are not rendered by default.

src/QAToolKit.Engine.Bombardier.Test/BombardierTestsRunnerTests.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ public BombardierTestsRunnerTests(ITestOutputHelper testOutputHelper)
2626
[IgnoreOnGithubFact]
2727
public async Task BombardierGetTestWithOptionsTest_Successfull()
2828
{
29+
var content = File.ReadAllText("Assets/getPetById.json");
30+
var httpRequest = JsonConvert.DeserializeObject<IEnumerable<HttpRequest>>(content);
2931

30-
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
32+
var bombardierTestsGenerator = new BombardierTestsGenerator(httpRequest, options =>
3133
{
3234
options.BombardierConcurrentUsers = 1;
3335
options.BombardierDuration = 1;
3436
options.BombardierTimeout = 30;
3537
options.BombardierUseHttp2 = true;
3638
});
3739

38-
var content = File.ReadAllText("Assets/getPetById.json");
39-
var httpRequest = JsonConvert.DeserializeObject<IEnumerable<HttpRequest>>(content);
40-
41-
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
40+
var bombardierTests = await bombardierTestsGenerator.Generate();
4241

4342
//Run Bombardier Tests
4443
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(), options =>
@@ -70,8 +69,10 @@ public async Task BombardierGetTestWithOptionsTest_Successfull()
7069
[IgnoreOnGithubFact]
7170
public async Task BombardierPostTestWithOptionsTest_Successfull()
7271
{
72+
var content = File.ReadAllText("Assets/addPet.json");
73+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
7374

74-
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
75+
var bombardierTestsGenerator = new BombardierTestsGenerator(httpRequest, options =>
7576
{
7677
options.BombardierConcurrentUsers = 1;
7778
options.BombardierDuration = 1;
@@ -84,10 +85,7 @@ public async Task BombardierPostTestWithOptionsTest_Successfull()
8485
});
8586
});
8687

87-
var content = File.ReadAllText("Assets/addPet.json");
88-
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
89-
90-
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
88+
var bombardierTests = await bombardierTestsGenerator.Generate();
9189

9290
//Run Bombardier Tests
9391
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(), options =>
@@ -119,8 +117,10 @@ public async Task BombardierPostTestWithOptionsTest_Successfull()
119117
[IgnoreOnGithubFact]
120118
public async Task BombardierPostTestWithBodyAndOptionsTest_Successfull()
121119
{
120+
var content = File.ReadAllText("Assets/AddBike.json");
121+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
122122

123-
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
123+
var bombardierTestsGenerator = new BombardierTestsGenerator(httpRequest, options =>
124124
{
125125
options.BombardierConcurrentUsers = 1;
126126
options.BombardierDuration = 1;
@@ -131,10 +131,7 @@ public async Task BombardierPostTestWithBodyAndOptionsTest_Successfull()
131131
});
132132
});
133133

134-
var content = File.ReadAllText("Assets/AddBike.json");
135-
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
136-
137-
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
134+
var bombardierTests = await bombardierTestsGenerator.Generate();
138135

139136
//Run Bombardier Tests
140137
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(), options =>

src/QAToolKit.Engine.Bombardier/BombardierGeneratorOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class BombardierGeneratorOptions
3838
/// <summary>
3939
/// Bombardier test runner duration
4040
/// </summary>
41-
public int BombardierDuration { get; set; } = 5;
41+
public int BombardierDuration { get; set; } = 10;
4242
/// <summary>
4343
/// Bombardier rate limiting per second
4444
/// </summary>

src/QAToolKit.Engine.Bombardier/BombardierTestsGenerator.cs

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,42 @@ namespace QAToolKit.Engine.Bombardier
1515
/// <summary>
1616
/// Bombardier test generator
1717
/// </summary>
18-
public class BombardierTestsGenerator : IGenerator<IEnumerable<HttpRequest>, IEnumerable<BombardierTest>>
18+
public class BombardierTestsGenerator
1919
{
20+
private readonly IEnumerable<HttpRequest> _httpRequests;
2021
private readonly BombardierGeneratorOptions _bombardierGeneratorOptions;
2122

2223
/// <summary>
2324
/// Bombardier test generator constructor
2425
/// </summary>
26+
/// <param name="httpRequests"></param>
2527
/// <param name="options"></param>
26-
public BombardierTestsGenerator(Action<BombardierGeneratorOptions> options = null)
28+
public BombardierTestsGenerator(IEnumerable<HttpRequest> httpRequests, Action<BombardierGeneratorOptions> options = null)
2729
{
30+
_httpRequests = httpRequests ?? throw new ArgumentNullException(nameof(httpRequests));
2831
_bombardierGeneratorOptions = new BombardierGeneratorOptions();
2932
options?.Invoke(_bombardierGeneratorOptions);
3033
}
3134

3235
/// <summary>
33-
/// Generate a Bombardier script from requests
36+
/// Generate a Bombardier scripts from requests
3437
/// </summary>
3538
/// <returns></returns>
36-
/// <param name="source"></param>
37-
public Task<IEnumerable<BombardierTest>> Generate(IEnumerable<HttpRequest> source)
39+
public Task<IEnumerable<BombardierTest>> Generate()
3840
{
39-
if (source == null)
40-
throw new ArgumentNullException(nameof(source));
41+
string bombardierFullPath = GetBombardierPath();
4142

4243
var bombardierTests = new List<BombardierTest>();
44+
foreach (var request in _httpRequests)
45+
{
46+
bombardierTests.Add(GenerateScript(bombardierFullPath, request));
47+
}
48+
49+
return Task.FromResult(bombardierTests.AsEnumerable());
50+
}
4351

52+
private static string GetBombardierPath()
53+
{
4454
string bombardierFullPath;
4555

4656
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -52,31 +62,32 @@ public Task<IEnumerable<BombardierTest>> Generate(IEnumerable<HttpRequest> sourc
5262
bombardierFullPath = Path.Combine("./bombardier", "linux", "bombardier");
5363
}
5464

55-
foreach (var request in source)
56-
{
57-
var scriptBuilder = new StringBuilder();
58-
scriptBuilder.Append($"{bombardierFullPath} " +
59-
$"-m {request.Method.ToString().ToUpper()} {HttpUrlHelper.GenerateUrlParameters(request, _bombardierGeneratorOptions)}" +
60-
$"{BombardierSwitchGeneratorHelper.GenerateConcurrentSwitch(_bombardierGeneratorOptions)}" +
61-
$"{AuthorizationHeaderHelper.GenerateAuthHeader(request, _bombardierGeneratorOptions)}" +
62-
$"{ContentTypeHeaderHelper.GenerateContentTypeHeader(request, _bombardierGeneratorOptions.BombardierBodyContentType)}" +
63-
$"{BombardierSwitchGeneratorHelper.GenerateBodySwitch(request, _bombardierGeneratorOptions)}" +
64-
$"{BombardierSwitchGeneratorHelper.GenerateHttpProtocolSwitch(_bombardierGeneratorOptions)}" +
65-
$"{BombardierSwitchGeneratorHelper.GenerateTimeoutSwitch(_bombardierGeneratorOptions)}" +
66-
$"{BombardierSwitchGeneratorHelper.GenerateDurationSwitch(_bombardierGeneratorOptions)}" +
67-
$"{BombardierSwitchGeneratorHelper.GenerateInsecureSwitch(_bombardierGeneratorOptions)}" +
68-
$"{BombardierSwitchGeneratorHelper.GenerateRateLimitSwitch(_bombardierGeneratorOptions)}" +
69-
$"{BombardierSwitchGeneratorHelper.GenerateTotalRequestsSwitch(_bombardierGeneratorOptions)}");
65+
return bombardierFullPath;
66+
}
7067

71-
bombardierTests.Add(new BombardierTest()
72-
{
73-
Url = new Uri(HttpUrlHelper.GenerateUrlParameters(request, _bombardierGeneratorOptions), UriKind.Absolute),
74-
Method = request.Method,
75-
Command = scriptBuilder.ToString()
76-
});
77-
}
68+
private BombardierTest GenerateScript(string bombardierFullPath, HttpRequest request)
69+
{
70+
var scriptBuilder = new StringBuilder();
71+
scriptBuilder.Append($"{bombardierFullPath} " +
72+
$"-m {request.Method.ToString().ToUpper()} {HttpUrlHelper.GenerateUrlParameters(request, _bombardierGeneratorOptions)}" +
73+
$"{BombardierSwitchGeneratorHelper.GenerateConcurrentSwitch(_bombardierGeneratorOptions)}" +
74+
$"{AuthorizationHeaderHelper.GenerateAuthHeader(request, _bombardierGeneratorOptions)}" +
75+
$"{ContentTypeHeaderHelper.GenerateContentTypeHeader(request, _bombardierGeneratorOptions.BombardierBodyContentType)}" +
76+
$"{BombardierSwitchGeneratorHelper.GenerateBodySwitch(request, _bombardierGeneratorOptions)}" +
77+
$"{BombardierSwitchGeneratorHelper.GenerateHttpProtocolSwitch(_bombardierGeneratorOptions)}" +
78+
$"{BombardierSwitchGeneratorHelper.GenerateTimeoutSwitch(_bombardierGeneratorOptions)}" +
79+
$"{BombardierSwitchGeneratorHelper.GenerateDurationSwitch(_bombardierGeneratorOptions)}" +
80+
$"{BombardierSwitchGeneratorHelper.GenerateInsecureSwitch(_bombardierGeneratorOptions)}" +
81+
$"{BombardierSwitchGeneratorHelper.GenerateRateLimitSwitch(_bombardierGeneratorOptions)}" +
82+
$"{BombardierSwitchGeneratorHelper.GenerateTotalRequestsSwitch(_bombardierGeneratorOptions)}");
7883

79-
return Task.FromResult(bombardierTests.AsEnumerable());
84+
return new BombardierTest()
85+
{
86+
Url = new Uri(HttpUrlHelper.GenerateUrlParameters(request, _bombardierGeneratorOptions), UriKind.Absolute),
87+
Method = request.Method,
88+
Command = scriptBuilder.ToString(),
89+
OperationId = request.OperationId ?? null
90+
};
8091
}
8192
}
8293
}

src/QAToolKit.Engine.Bombardier/BombardierTestsRunner.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@ public class BombardierTestsRunner
2525
/// <param name="options"></param>
2626
public BombardierTestsRunner(IEnumerable<BombardierTest> bombardierTests, Action<BombardierOutputOptions> options = null)
2727
{
28-
_bombardierTests = bombardierTests;
28+
_bombardierTests = bombardierTests ?? throw new ArgumentNullException(nameof(bombardierTests));
2929
_bombardierParserOptions = new BombardierOutputOptions();
30-
31-
if (options == null)
32-
{
33-
_bombardierParserOptions.ObfuscateAuthenticationHeader = true;
34-
}
35-
else
36-
{
37-
options?.Invoke(_bombardierParserOptions);
38-
}
30+
options?.Invoke(_bombardierParserOptions);
3931
}
4032

4133
/// <summary>

src/QAToolKit.Engine.Bombardier/Helpers/BombardierSwitchGeneratorHelper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using QAToolKit.Core.Models;
2+
using QAToolKit.Engine.Bombardier.Exceptions;
23
using System;
34

45
namespace QAToolKit.Engine.Bombardier.Helpers
@@ -31,6 +32,12 @@ internal static string GenerateInsecureSwitch(BombardierGeneratorOptions bombard
3132
/// <returns></returns>
3233
internal static string GenerateTotalRequestsSwitch(BombardierGeneratorOptions bombardierOptions)
3334
{
35+
if(bombardierOptions.BombardierRateLimit != null &&
36+
bombardierOptions.BombardierNumberOfTotalRequests != null)
37+
{
38+
throw new QAToolKitBombardierException("BombardierRateLimit and BombardierNumberOfTotalRequests settings are mutually exclusive. Please use one or the other.");
39+
}
40+
3441
if (bombardierOptions.BombardierNumberOfTotalRequests != null)
3542
{
3643
return $" --requests={bombardierOptions.BombardierNumberOfTotalRequests}";
@@ -45,6 +52,12 @@ internal static string GenerateTotalRequestsSwitch(BombardierGeneratorOptions bo
4552
/// <returns></returns>
4653
internal static string GenerateRateLimitSwitch(BombardierGeneratorOptions bombardierOptions)
4754
{
55+
if (bombardierOptions.BombardierRateLimit != null &&
56+
bombardierOptions.BombardierNumberOfTotalRequests != null)
57+
{
58+
throw new QAToolKitBombardierException("BombardierRateLimit and BombardierNumberOfTotalRequests settings are mutually exclusive. Please use one or the other.");
59+
}
60+
4861
if (bombardierOptions.BombardierRateLimit != null)
4962
{
5063
return $" --rate={bombardierOptions.BombardierRateLimit}";

src/QAToolKit.Engine.Bombardier/Models/BombardierTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ public class BombardierTest
2020
/// Bombardier command
2121
/// </summary>
2222
public string Command { get; set; }
23+
/// <summary>
24+
/// Operation Id
25+
/// </summary>
26+
public string OperationId { get; set; }
2327
}
2428
}

0 commit comments

Comments
 (0)