Skip to content

Commit 1da3098

Browse files
authored
Before release merge to main
* new tests, updated with latest core library * bombardier binaries update, more tests, bombardier inline JSON body instead of files, switch generation improvement * bombardier generators refactorings * helpers refactored, replacement values introduced, more tests * alpha 1 * nuget tests update, readme file update * POST and PUT tests * custome xception, HTTP DELETE test, cleanup * cleanup * run real load tests only in debug * xunit fact attribute * relacement values to dictionary, additional tests * code analysis yml and run build only on pull request
1 parent 21c2c64 commit 1da3098

33 files changed

+3155
-353
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
# ******** NOTE ********
12+
13+
name: "CodeQL"
14+
15+
on:
16+
pull_request:
17+
branches: [ develop ]
18+
schedule:
19+
- cron: '36 12 * * 3'
20+
21+
jobs:
22+
analyze:
23+
name: Analyze
24+
runs-on: ubuntu-latest
25+
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
language: [ 'csharp' ]
30+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
31+
# Learn more...
32+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
# Initializes the CodeQL tools for scanning.
39+
- name: Initialize CodeQL
40+
uses: github/codeql-action/init@v1
41+
with:
42+
languages: ${{ matrix.language }}
43+
# If you wish to specify custom queries, you can do so here or in a config file.
44+
# By default, queries listed here will override any specified in a config file.
45+
# Prefix the list here with "+" to use these queries and those in the config file.
46+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
47+
48+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
49+
# If this step fails, then you should remove it and run the build manually (see below)
50+
- name: Autobuild
51+
uses: github/codeql-action/autobuild@v1
52+
53+
# ℹ️ Command-line programs to run using the OS shell.
54+
# 📚 https://git.io/JvXDl
55+
56+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
57+
# and modify them (or add more) to build your code if your project
58+
# uses a compiled language
59+
60+
#- run: |
61+
# make bootstrap
62+
# make release
63+
64+
- name: Perform CodeQL Analysis
65+
uses: github/codeql-action/analyze@v1

.github/workflows/dotnet-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Build .NET Library
22

33
on:
4-
push:
54
pull_request:
5+
branches: [ develop, main ]
66
release:
77
types:
88
- published

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.1.1</Version>
3+
<Version>0.1.6</Version>
44
</PropertyGroup>
55
</Project>

README.md

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
# QAToolKit.Engine.Bombardier
22
![.NET Core](https://github.com/qatoolkit/qatoolkit-engine-bombardier-net/workflows/.NET%20Core/badge.svg?branch=main)
33

4-
`QAToolKit.Engine.Bombardier` is a .NET standard library, which takes `IList<HttpTestRequest>` object and runs load tests with tool called [Bombardier](https://github.com/codesenberg/bombardier).
4+
`QAToolKit.Engine.Bombardier` is a .NET standard library, which takes `IEnumerable<HttpTestRequest>` object and runs load tests with tool called [Bombardier](https://github.com/codesenberg/bombardier).
55

66
Library is a thin wrapper, that generates requests and parses results so you can export them to whatever format you prefer.
77

88
Major features:
99

10-
- Library takes `IList<HttpTestRequest>` object, which can be produced in your code or can be imported from other sources. One example can be QAToolKit Swagger library that can produce that object with many options. Check it out [here](https://github.com/qatoolkit/qatoolkit-source-swagger-net).
10+
- Library takes `IEnumerable<HttpTestRequest>` object, which can be produced in your code or can be imported from other sources. One example can be QAToolKit Swagger library that can produce that object with many options. Check it out [here](https://github.com/qatoolkit/qatoolkit-source-swagger-net).
1111
- Generate a Bombardier report that can be exported to the format you want.
1212

13+
Bombardier version [1.2.5](https://github.com/codesenberg/bombardier/releases/tag/v1.2.5) is used for `windows-amd64` and `linux-amd64`.
14+
1315
## Sample
1416

1517
```csharp
18+
//Generate requests from previously stored JSON file:
19+
var content = File.ReadAllText("Assets/getPetById.json");
20+
var httpRequest = JsonConvert.DeserializeObject<IEnumerable<HttpRequest>>(content);
1621

17-
//Instantiate a Bombardier test generator, by specifying Bombardier options
22+
//Create bombardier tests generator
1823
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
1924
{
20-
//if your api endpoints you are testing are protected by Oauth2 access tokens
21-
options.AddOAuth2Token("eyJhbGciOiJSUzI1N....", AuthenticationType.Customer);
22-
//if your api endpoints are protected by simple "ApiKey: <apikey>" authentication header
23-
options.AddApiKey("myAPIKey123423456");
24-
//if your api endpoints are protected by basic authentication
25-
options.AddBasicAuthentication("username", "password");
2625
options.BombardierConcurrentUsers = 1;
2726
options.BombardierDuration = 1;
2827
options.BombardierTimeout = 30;
2928
options.BombardierUseHttp2 = true;
3029
});
31-
//Generate Bombardier Tests
32-
var bombardierTests = await bombardierTestsGenerator.Generate(requests);
30+
31+
//Generate bomardier tests
32+
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
3333

3434
//Run Bombardier Tests
35-
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(),
36-
options =>
37-
{
38-
options.ObfuscateAuthenticationHeader = false;
39-
});
35+
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(), options =>
36+
{
37+
options.ObfuscateAuthenticationHeader = true;
38+
});
4039
var bombardierResults = await bombardierTestsRunner.Run();
4140
```
4241

@@ -80,27 +79,65 @@ Use `AddApiKey` if your APIs are protected by simple API Key. Pass Api Key in th
8079
##### 1.3 AddBasicAuthentication
8180
Use `AddBasicAuthentication` if your APIs are protected by basic authentication. Pass username and password in the method. A basic `Authentication` HTTP header will be generated. This is not best practice, but it's here if you need it.
8281

83-
#### 2. Bombardier parameters
82+
##### 1.4 AddReplacementValues
83+
When you use `AddReplacementValues` values those can set or replace URL and HTTP body parameters before executing the tests. Replacement values have precedence over the `example` values that are set in Swagger file.
8484

85-
You can set 5 Bombardier properties:
86-
87-
- `BombardierConcurrentUsers`: How many concurrent users should be used in Bombardier tests.
88-
- `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`.
89-
- `BombardierTimeout`: What is the Bombardier timeout to wait for the requests to finish.
90-
- `BombardierUseHttp2`: Use HTTP2?
91-
- `BombardierRateLimit`: Rate limit Bombardier tests per second. Use this depending on the type of test you want to perform and should not be used with `BombardierDuration`.
85+
#### 2. Bombardier parameters
9286

87+
You can also set those `BombardierGeneratorOptions` options:
88+
89+
- `BombardierConcurrentUsers`: How many concurrent users should be used in Bombardier tests. Default is `3`.
90+
- `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.
91+
- `BombardierTimeout`: What is the Bombardier timeout to wait for the requests to finish. Default is `30` seconds.
92+
- `BombardierUseHttp2`: Use HTTP2 protocol. Otherwise HTTP1 is used. By default this is set to `true`.
93+
- `BombardierRateLimit`: Rate limit Bombardier tests per second. Use this depending on the type of test you want to perform and should not be used with `BombardierDuration`. By default rate limit is not set.
94+
- `BombardierNumberOfTotalRequests`: Limit the test to run only certain amount of requests. By default total number of requests is not set.
95+
- `BombardierInsecure`: Instead of HTTPS use HTTP protocol. Default value is `false`.
96+
- `BombardierBodyContentType`: Force only certain HTTP Content type. By default is set to `application/json`.
97+
9398
#### 3. Obfuscate Auth tokens for Bombardier output
9499

95100
Output is obfuscated by default, but you can turn it off with `options.ObfuscateAuthenticationHeader = false;` in `BombardierTestsRunner` options.
96101

97102
## How to use
98103

99-
TO-DO
104+
In the sample code above we generate HTTP requests from previously generated object which was serialized to JSON.
105+
106+
If you use Swagger files, you need to check the `QAToolKit.Source.Swagger` NuGet package, where you can generate that object from the Swagger file.
107+
108+
Let's replace
109+
110+
```csharp
111+
//Generate requests from previously stored JSON file:
112+
var content = File.ReadAllText("Assets/getPetById.json");
113+
var httpRequest = JsonConvert.DeserializeObject<IEnumerable<HttpRequest>>(content);
114+
```
115+
116+
with
117+
118+
```csharp
119+
//Setup Swagger source
120+
var urlSource = new SwaggerUrlSource(options =>
121+
{
122+
options.AddBaseUrl(new Uri("https://qatoolkitapi.azurewebsites.net/"));
123+
options.AddRequestFilters(new RequestFilter()
124+
{
125+
EndpointNameWhitelist = new string[] { "GetAllBikes" }
126+
});
127+
options.UseSwaggerExampleValues = true;
128+
});
129+
130+
//Load requests object
131+
var requests = await urlSource.Load(new Uri[] {
132+
new Uri("https://qatoolkitapi.azurewebsites.net/swagger/v1/swagger.json")
133+
});
134+
```
135+
136+
in the sample code above. Check the [QAToolKit.Source.Swagger](https://github.com/qatoolkit/qatoolkit-source-swagger-net) library for more details.
100137

101138
## TO-DO
102139

103-
N/A
140+
- Currently tested for GET, POST, PUT and DELETE HTTP methods. Need to extend support.
104141

105142
## License
106143

bombardier/linux/bombardier

-848 KB
Binary file not shown.

bombardier/win/bombardier.exe

-50.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)