Skip to content

Commit ee3b7cf

Browse files
committed
new tests, updated with latest core library
1 parent 21c2c64 commit ee3b7cf

File tree

11 files changed

+1047
-50
lines changed

11 files changed

+1047
-50
lines changed

src/QAToolKit.Engine.Bombardier.Test/Assets/addPet.json

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 186 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,186 @@
1-
[{"BasePath":"https://petstore3.swagger.io/api/v3","Path":"/pet/1","OperationId":"getPetById","Method":{"Method":"GET"},"Summary":"Find pet by ID","Description":"Returns a single pet","Tags":["pet"],"Parameters":[{"Name":"petId","Type":"integer","Nullable":false,"Value":"1"}],"RequestBodies":[],"Responses":[{"StatusCode":"200","Properties":[{"Name":"id","Description":null,"Type":"integer","Value":null},{"Name":"name","Description":null,"Type":"string","Value":null},{"Name":"category","Description":null,"Type":"object","Value":null},{"Name":"photoUrls","Description":null,"Type":"array","Value":null},{"Name":"tags","Description":null,"Type":"array","Value":null},{"Name":"status","Description":"pet status in the store","Type":"string","Value":null}]},{"StatusCode":"400","Properties":[]},{"StatusCode":"404","Properties":[]}],"TestTypes":[],"AuthenticationTypes":[]}]
1+
[
2+
{
3+
"BasePath": "https://petstore3.swagger.io/api/v3",
4+
"Path": "/pet/10",
5+
"OperationId": "getPetById",
6+
"Method": {
7+
"Method": "GET"
8+
},
9+
"Summary": "Find pet by ID",
10+
"Description": "Returns a single pet",
11+
"Tags": [
12+
"pet"
13+
],
14+
"Parameters": [
15+
{
16+
"Name": "petId",
17+
"Type": "integer",
18+
"Nullable": false,
19+
"Value": null,
20+
"Required": true,
21+
"Location": 1
22+
}
23+
],
24+
"RequestBodies": [],
25+
"Responses": [
26+
{
27+
"StatusCode": 200,
28+
"Type": 2,
29+
"Properties": [
30+
{
31+
"Name": "id",
32+
"Description": null,
33+
"Format": "int64",
34+
"Type": "integer",
35+
"Value": "10",
36+
"Required": false,
37+
"Properties": null
38+
},
39+
{
40+
"Name": "name",
41+
"Description": null,
42+
"Format": null,
43+
"Type": "string",
44+
"Value": "doggie",
45+
"Required": false,
46+
"Properties": null
47+
},
48+
{
49+
"Name": "Category",
50+
"Description": null,
51+
"Format": null,
52+
"Type": "object",
53+
"Value": null,
54+
"Required": false,
55+
"Properties": [
56+
{
57+
"Name": "id",
58+
"Description": null,
59+
"Format": "int64",
60+
"Type": "integer",
61+
"Value": "1",
62+
"Required": false,
63+
"Properties": null
64+
},
65+
{
66+
"Name": "name",
67+
"Description": null,
68+
"Format": null,
69+
"Type": "string",
70+
"Value": "Dogs",
71+
"Required": false,
72+
"Properties": null
73+
}
74+
]
75+
},
76+
{
77+
"Name": "photoUrls",
78+
"Description": null,
79+
"Format": null,
80+
"Type": "array",
81+
"Value": null,
82+
"Required": false,
83+
"Properties": [
84+
{
85+
"Name": null,
86+
"Description": null,
87+
"Format": null,
88+
"Type": "string",
89+
"Value": null,
90+
"Required": false,
91+
"Properties": null
92+
}
93+
]
94+
},
95+
{
96+
"Name": "tags",
97+
"Description": null,
98+
"Format": null,
99+
"Type": "array",
100+
"Value": null,
101+
"Required": false,
102+
"Properties": [
103+
{
104+
"Name": "Tag",
105+
"Description": null,
106+
"Format": null,
107+
"Type": "object",
108+
"Value": null,
109+
"Required": false,
110+
"Properties": [
111+
{
112+
"Name": "id",
113+
"Description": null,
114+
"Format": "int64",
115+
"Type": "integer",
116+
"Value": null,
117+
"Required": false,
118+
"Properties": null
119+
},
120+
{
121+
"Name": "name",
122+
"Description": null,
123+
"Format": null,
124+
"Type": "string",
125+
"Value": null,
126+
"Required": false,
127+
"Properties": null
128+
}
129+
]
130+
}
131+
]
132+
},
133+
{
134+
"Name": "status",
135+
"Description": "pet status in the store",
136+
"Format": null,
137+
"Type": "enum",
138+
"Value": null,
139+
"Required": false,
140+
"Properties": [
141+
{
142+
"Name": null,
143+
"Description": null,
144+
"Format": null,
145+
"Type": "string",
146+
"Value": "available",
147+
"Required": false,
148+
"Properties": null
149+
},
150+
{
151+
"Name": null,
152+
"Description": null,
153+
"Format": null,
154+
"Type": "string",
155+
"Value": "pending",
156+
"Required": false,
157+
"Properties": null
158+
},
159+
{
160+
"Name": null,
161+
"Description": null,
162+
"Format": null,
163+
"Type": "string",
164+
"Value": "sold",
165+
"Required": false,
166+
"Properties": null
167+
}
168+
]
169+
}
170+
]
171+
},
172+
{
173+
"StatusCode": 400,
174+
"Type": 1,
175+
"Properties": null
176+
},
177+
{
178+
"StatusCode": 404,
179+
"Type": 1,
180+
"Properties": null
181+
}
182+
],
183+
"TestTypes": [],
184+
"AuthenticationTypes": []
185+
}
186+
]
Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1+
using Microsoft.Extensions.Logging;
12
using Newtonsoft.Json;
23
using QAToolKit.Core.Models;
4+
using QAToolKit.Core.Test;
35
using System;
46
using System.Collections.Generic;
57
using System.IO;
68
using System.Linq;
79
using System.Net.Http;
810
using System.Threading.Tasks;
911
using Xunit;
12+
using Xunit.Abstractions;
1013

1114
namespace QAToolKit.Engine.Bombardier.Test
1215
{
1316
public class BombardierTestsGeneratorTests
1417
{
18+
private readonly ILogger<BombardierTestsGeneratorTests> _logger;
19+
20+
public BombardierTestsGeneratorTests(ITestOutputHelper testOutputHelper)
21+
{
22+
var loggerFactory = new LoggerFactory();
23+
loggerFactory.AddProvider(new XunitLoggerProvider(testOutputHelper));
24+
_logger = loggerFactory.CreateLogger<BombardierTestsGeneratorTests>();
25+
}
26+
1527
[Fact]
16-
public async Task GenerateBombardierTestWithOptionsTest_Successfull()
28+
public async Task GenerateBombardierTestWithOptionsVariation1Test_Successfull()
1729
{
1830

1931
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
@@ -25,19 +37,19 @@ public async Task GenerateBombardierTestWithOptionsTest_Successfull()
2537
});
2638

2739
var content = File.ReadAllText("Assets/getPetById.json");
28-
var httpRequest = JsonConvert.DeserializeObject<IList<HttpTestRequest>>(content);
40+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
2941

3042
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
3143

3244
Assert.NotNull(bombardierTests);
3345
Assert.Single(bombardierTests);
34-
Assert.Contains(" -m GET https://petstore3.swagger.io/api/v3/pet/1?petId=1 -c 1 --http2 --timeout=30s --duration=1s", bombardierTests.FirstOrDefault().Command);
46+
Assert.Contains(" -m GET https://petstore3.swagger.io/api/v3/pet/10 -c 1 --http2 --timeout=30s --duration=1s", bombardierTests.FirstOrDefault().Command);
3547
Assert.Equal(HttpMethod.Get, bombardierTests.FirstOrDefault().Method);
36-
Assert.Equal("/pet/1", bombardierTests.FirstOrDefault().Url.ToString());
48+
Assert.Equal("/pet/10", bombardierTests.FirstOrDefault().Url.ToString());
3749
}
3850

3951
[Fact]
40-
public async Task GenerateBombardierTestWithOptionsAlternativeTest_Successfull()
52+
public async Task GenerateBombardierTestWithOptionsVariation2Test_Successfull()
4153
{
4254

4355
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
@@ -50,52 +62,64 @@ public async Task GenerateBombardierTestWithOptionsAlternativeTest_Successfull()
5062
});
5163

5264
var content = File.ReadAllText("Assets/getPetById.json");
53-
var httpRequest = JsonConvert.DeserializeObject<IList<HttpTestRequest>>(content);
65+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
5466

5567
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
5668

5769
Assert.NotNull(bombardierTests);
5870
Assert.Single(bombardierTests);
59-
Assert.Contains(" -m GET https://petstore3.swagger.io/api/v3/pet/1?petId=1 -c 1 --http2 --timeout=30s --duration=10s --insecure", bombardierTests.FirstOrDefault().Command);
71+
Assert.Contains(" -m GET https://petstore3.swagger.io/api/v3/pet/10 -c 1 --http2 --timeout=30s --duration=10s --insecure", bombardierTests.FirstOrDefault().Command);
6072
Assert.Equal(HttpMethod.Get, bombardierTests.FirstOrDefault().Method);
61-
Assert.Equal("/pet/1", bombardierTests.FirstOrDefault().Url.ToString());
73+
Assert.Equal("/pet/10", bombardierTests.FirstOrDefault().Url.ToString());
6274
}
6375

64-
/* [Fact]
65-
public async Task BombardierTestWithOptionsTest_Successfull()
76+
[Fact]
77+
public async Task GenerateBombardierTestWithOptionsVariation3Test_Successfull()
6678
{
6779

6880
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
6981
{
7082
options.BombardierConcurrentUsers = 1;
7183
options.BombardierDuration = 1;
7284
options.BombardierTimeout = 30;
73-
options.BombardierUseHttp2 = true;
85+
options.BombardierUseHttp2 = false;
7486
});
7587

7688
var content = File.ReadAllText("Assets/getPetById.json");
77-
var httpRequest = JsonConvert.DeserializeObject<IList<HttpTestRequest>>(content);
89+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
7890

7991
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
8092

81-
//Run Bombardier Tests
82-
var bombardierTestsRunner = new BombardierTestsRunner(bombardierTests.ToList(), options =>
93+
Assert.NotNull(bombardierTests);
94+
Assert.Single(bombardierTests);
95+
Assert.Contains(" -m GET https://petstore3.swagger.io/api/v3/pet/10 -c 1 --http1 --timeout=30s --duration=1s", bombardierTests.FirstOrDefault().Command);
96+
Assert.Equal(HttpMethod.Get, bombardierTests.FirstOrDefault().Method);
97+
Assert.Equal("/pet/10", bombardierTests.FirstOrDefault().Url.ToString());
98+
}
99+
100+
[Fact]
101+
public async Task GenerateBombardierTestWithOptionsVariation4Test_Successfull()
102+
{
103+
104+
var bombardierTestsGenerator = new BombardierTestsGenerator(options =>
83105
{
84-
options.ObfuscateAuthenticationHeader = true;
106+
options.BombardierConcurrentUsers = 1;
107+
options.BombardierDuration = 1;
108+
options.BombardierTimeout = 30;
109+
options.BombardierUseHttp2 = true;
110+
options.BombardierRateLimit = 20;
85111
});
86-
var bombardierResults = await bombardierTestsRunner.Run();
87-
88-
Assert.NotNull(bombardierResults);
89-
Assert.Single(bombardierResults);
90-
Assert.True(bombardierResults.FirstOrDefault().AverageLatency > 0);
91-
Assert.True(bombardierResults.FirstOrDefault().MaxLatency > 0);
92-
Assert.True(bombardierResults.FirstOrDefault().StdevLatency > 0);
93-
Assert.True(bombardierResults.FirstOrDefault().AverageRequestsPerSecond > 0);
94-
Assert.True(bombardierResults.FirstOrDefault().MaxRequestsPerSecond > 0);
95-
Assert.True(bombardierResults.FirstOrDefault().StdevRequestsPerSecond > 0);
96-
Assert.True(bombardierResults.FirstOrDefault().TestStart.AddMinutes(60) > DateTime.Now);
97-
Assert.True(bombardierResults.FirstOrDefault().TestStop.AddMinutes(60) > DateTime.Now);
98-
Assert.True(bombardierResults.FirstOrDefault().TestStop.Subtract(bombardierResults.FirstOrDefault().TestStart).TotalSeconds == bombardierResults.FirstOrDefault().Duration);
99-
}*/
112+
113+
var content = File.ReadAllText("Assets/getPetById.json");
114+
var httpRequest = JsonConvert.DeserializeObject<IList<HttpRequest>>(content);
115+
116+
var bombardierTests = await bombardierTestsGenerator.Generate(httpRequest);
117+
118+
Assert.NotNull(bombardierTests);
119+
Assert.Single(bombardierTests);
120+
Assert.Contains(" -m GET https://petstore3.swagger.io/api/v3/pet/10 -c 1 --http2 --timeout=30s --duration=1s --rate=20", bombardierTests.FirstOrDefault().Command);
121+
Assert.Equal(HttpMethod.Get, bombardierTests.FirstOrDefault().Method);
122+
Assert.Equal("/pet/10", bombardierTests.FirstOrDefault().Url.ToString());
123+
}
100124
}
101125
}

0 commit comments

Comments
 (0)