Skip to content

Commit bd095ab

Browse files
committed
Adding Load Testing Script and Config
1 parent c5fdc00 commit bd095ab

File tree

6 files changed

+162
-7
lines changed

6 files changed

+162
-7
lines changed

.github/workflows/workflow.yml

+36-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
name: Build-Deploy-WebApp
22
on: [push]
3+
#Change it with your own resources
34
env:
45
AZURE_WEBAPP_NAME: loadtestingweb
56
AZURE_WEBAPP_PACKAGE_PATH: 'LoadTestingWebApp'
7+
LOAD_TEST_RESOURCE_GROUP: 'LoadTestingSample'
8+
LOAD_TEST_RESOURCE: 'LoadTestingWebApp'
69
DOTNET_VERSION: '7.0.x'
710
jobs:
8-
build:
11+
Build-Deploy:
12+
name: Build-Deploy
913
runs-on: ubuntu-latest
1014
steps:
1115
- uses: actions/checkout@main
@@ -18,10 +22,39 @@ jobs:
1822
dotnet restore
1923
dotnet build --configuration Release
2024
dotnet publish -c Release -o '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/LoadTestingWebApp'
21-
# Deploy to Azure Web apps
2225
- name: 'Deploy to Azure'
2326
uses: azure/webapps-deploy@v2
2427
with:
2528
app-name: ${{ env.AZURE_WEBAPP_NAME }}
29+
# Add a GitHub Secret for the Azure Web App Publishing Profile
2630
publish-profile: ${{ secrets.AZURE_WEBAPP_SECRET }}
27-
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/LoadTestingWebApp'
31+
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/LoadTestingWebApp'
32+
LoadTest:
33+
name: LoadTest
34+
needs: Build-Deploy
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@main
38+
- name: Login to Azure
39+
uses: azure/login@v1
40+
continue-on-error: false
41+
with:
42+
# Add an Azure Credential in GitHub Secrets to connect with Azure Load Testing
43+
creds: ${{ secrets.AZURE_CREDENTIALS }}
44+
- name: 'Azure Load Testing'
45+
uses: azure/load-testing@v1
46+
with:
47+
loadTestConfigFile: 'LoadTestingConfig.yaml'
48+
loadTestResource: ${{ env.LOAD_TEST_RESOURCE }}
49+
resourceGroup: ${{ env.LOAD_TEST_RESOURCE_GROUP }}
50+
env: |
51+
[
52+
{
53+
"name": "webapp",
54+
"value": "${{ env.AZURE_WEBAPP_NAME }}.azurewebsites.net"
55+
}
56+
]
57+
- uses: actions/upload-artifact@v2
58+
with:
59+
name: loadTestResults
60+
path: ${{ github.workspace }}/LoadTest

ARM/template.json

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
33
"contentVersion": "1.0.0.0",
44
"parameters": {
55
"location": {
@@ -26,9 +26,10 @@
2626
"variables": {
2727
"cosmos_name": "[concat('loadtestingcosmos',uniqueString(resourceGroup().id))]",
2828
"logs_name": "[concat('loadtestinglogs',uniqueString(resourceGroup().id))]",
29-
"plan_name": "[concat('loadtestingplan',uniqueString(resourceGroup().id))]",
29+
"plan_name": "[concat('loadtestingappplan',uniqueString(resourceGroup().id))]",
3030
"insights_name": "[concat('loadtestinginsights',uniqueString(resourceGroup().id))]",
31-
"app_name": "[concat('loadtestingweb',uniqueString(resourceGroup().id))]"
31+
"app_name": "[concat('loadtestingweb',uniqueString(resourceGroup().id))]",
32+
"loadtesting_name": "[concat('loadtesting',uniqueString(resourceGroup().id))]"
3233
},
3334
"resources": [
3435
{
@@ -136,6 +137,28 @@
136137
"virtualNetworkSubnetId": null,
137138
"httpsOnly": true
138139
}
140+
},
141+
{
142+
"type": "Microsoft.Web/sites/config",
143+
"apiVersion": "2020-12-01",
144+
"name": "[format('{0}/{1}', variables('app_name'), 'connectionstrings')]",
145+
"properties": {
146+
"Cosmos": {
147+
"value": "[listConnectionStrings(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('cosmos_name')), '2019-12-12').connectionStrings[0].connectionString]",
148+
"type": "Custom"
149+
}
150+
},
151+
"dependsOn": [
152+
"[resourceId('Microsoft.DocumentDb/databaseAccounts', variables('cosmos_name'))]",
153+
"[resourceId('Microsoft.Web/sites', variables('app_name'))]"
154+
]
155+
},
156+
{
157+
"type": "Microsoft.LoadTestService/loadtests",
158+
"apiVersion": "2022-12-01",
159+
"name": "[variables('loadtesting_name')]",
160+
"location": "[parameters('location')]",
161+
"tags": {}
139162
}
140163
],
141164
"outputs": {}

LoadTestingConfig.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: v0.1
2+
testName: LoadTesting
3+
testPlan: LoadTestingScript.jmx
4+
description: 'LoadTestingWebApp Test Run'
5+
engineInstances: 1
6+
failureCriteria:
7+
- avg(response_time_ms) > 5000
8+
- percentage(error) > 20

LoadTestingScript.jmx

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.5">
3+
<hashTree>
4+
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
5+
<stringProp name="TestPlan.comments"></stringProp>
6+
<boolProp name="TestPlan.functional_mode">false</boolProp>
7+
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
8+
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
9+
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
10+
<collectionProp name="Arguments.arguments"/>
11+
</elementProp>
12+
<stringProp name="TestPlan.user_define_classpath"></stringProp>
13+
</TestPlan>
14+
<hashTree>
15+
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
16+
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
17+
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
18+
<boolProp name="LoopController.continue_forever">false</boolProp>
19+
<stringProp name="LoopController.loops">1</stringProp>
20+
</elementProp>
21+
<stringProp name="ThreadGroup.num_threads">1000</stringProp>
22+
<stringProp name="ThreadGroup.ramp_time">3</stringProp>
23+
<boolProp name="ThreadGroup.scheduler">false</boolProp>
24+
<stringProp name="ThreadGroup.duration"></stringProp>
25+
<stringProp name="ThreadGroup.delay"></stringProp>
26+
<boolProp name="ThreadGroup.same_user_on_next_iteration">false</boolProp>
27+
</ThreadGroup>
28+
<hashTree>
29+
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="WebApp" enabled="true">
30+
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
31+
<collectionProp name="Arguments.arguments"/>
32+
</elementProp>
33+
<stringProp name="HTTPSampler.domain">loadtestingweb.azurewebsites.net</stringProp>
34+
<stringProp name="HTTPSampler.port">443</stringProp>
35+
<stringProp name="HTTPSampler.protocol">https</stringProp>
36+
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
37+
<stringProp name="HTTPSampler.path"></stringProp>
38+
<stringProp name="HTTPSampler.method">GET</stringProp>
39+
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
40+
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
41+
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
42+
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
43+
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
44+
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
45+
<stringProp name="HTTPSampler.response_timeout"></stringProp>
46+
</HTTPSamplerProxy>
47+
<hashTree/>
48+
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
49+
<boolProp name="ResultCollector.error_logging">false</boolProp>
50+
<objProp>
51+
<name>saveConfig</name>
52+
<value class="SampleSaveConfiguration">
53+
<time>true</time>
54+
<latency>true</latency>
55+
<timestamp>true</timestamp>
56+
<success>true</success>
57+
<label>true</label>
58+
<code>true</code>
59+
<message>true</message>
60+
<threadName>true</threadName>
61+
<dataType>true</dataType>
62+
<encoding>false</encoding>
63+
<assertions>true</assertions>
64+
<subresults>true</subresults>
65+
<responseData>false</responseData>
66+
<samplerData>false</samplerData>
67+
<xml>false</xml>
68+
<fieldNames>true</fieldNames>
69+
<responseHeaders>false</responseHeaders>
70+
<requestHeaders>false</requestHeaders>
71+
<responseDataOnError>false</responseDataOnError>
72+
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
73+
<assertionsResultsToSave>0</assertionsResultsToSave>
74+
<bytes>true</bytes>
75+
<sentBytes>true</sentBytes>
76+
<url>true</url>
77+
<threadCounts>true</threadCounts>
78+
<idleTime>true</idleTime>
79+
<connectTime>true</connectTime>
80+
</value>
81+
</objProp>
82+
<stringProp name="filename"></stringProp>
83+
</ResultCollector>
84+
<hashTree/>
85+
</hashTree>
86+
</hashTree>
87+
</hashTree>
88+
</jmeterTestPlan>

LoadTestingWebApp/LoadTestingWebApp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<ItemGroup>
1818
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
1919
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.2" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.Cosmos" Version="6.0.1" />
2021
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
2122
</ItemGroup>
2223

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ If you would like to try this demo/project. You will need to deploy the followin
1515

1616
You can use the following ARM template to deploy the resources needed:
1717

18-
[![Deploy to Azure](img/deploy.png)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fdsanchezcr%2FLoadTestingDemo%2Fmain%2FARM%2Ftemplate.json)
18+
[![Deploy to Azure](img/deploy.png)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fdsanchezcr%2FLoadTestingDemo%2Fmain%2FARM%2Ftemplate.json)
19+
20+
> Note: Azure Cosmos DB is going to be created using the [free tier](https://learn.microsoft.com/azure/cosmos-db/free-tier), which only allows one per subscription, if you have already another Cosmos DB free tier, you will get a deployment error.

0 commit comments

Comments
 (0)