Skip to content

Commit dfbbb2d

Browse files
committed
Added load testing aspnetzero auth endpoint article
1 parent 48209bb commit dfbbb2d

10 files changed

+82
-0
lines changed

blog-posts/en/images/background.png

9.42 KB
Loading
Loading
Loading
Loading
87.5 KB
Loading
48.5 KB
Loading
9.78 KB
Loading
Loading
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Running Load Test on ASP.NET Zero
2+
3+
*Load testing* generally refers to the practice of modeling the expected usage of a software program by simulating multiple users accessing the program concurrently (from [Wikipedia](https://en.wikipedia.org/wiki/Load_testing)).
4+
5+
One of the most important part of a website is the login/authenticate endpoint. In this article, I will try to explain you how to load test authenticate endpoint on an ASP.NET Zero app. Although this article is for ASP.NET Zero, it can be applied to any ASP.NET Boilerplate app and even an ASP.NET Core app.
6+
7+
ASP.NET Zero is a starting point for new web applications with a modern UI and SOLID architecture, with full source code. If you want to know more about ASP.NET Zero, you can check its website [https://aspnetzero.com/](https://aspnetzero.com/).
8+
9+
## Create the project
10+
11+
Before starting the test, we need a web project to test. So, go to [https://aspnetzero.com/download](https://aspnetzero.com/download) page and create your project. If you are not an ASP.NET Zero customer, you can create a project on [https://aspnetboilerplate.com/Templates](https://aspnetboilerplate.com/Templates), create a project and use it as well.
12+
13+
## Prepare Test Data
14+
15+
To test the authenticate endpoint, we need dummy user records. To do that, create a CSV file similar to the one in image below and create 500 rows. You can easily create two rows and scroll down to row 500 and Excel will create users with username admin1, admin2, admin3, etc...
16+
17+
![Load test sample data](images/load-test-sample-data.png)
18+
19+
If you are using ASP.NET Zero, you can easily import this excel to your database on User List page by using "Excel operations -> Import from Excel" action button.
20+
21+
After importing the user data, you can remove other columns than UserName and Password from the excel file and save it as a CSV file. We will use this final CSV file for our test.
22+
23+
## JMeter
24+
25+
The **Apache JMeter™** application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. We will use JMeter for our load test. So, go to [https://jmeter.apache.org/](https://jmeter.apache.org/) and download the latest version for your OS.
26+
27+
### Thread Group
28+
29+
First add a Thread Group to your Test by right clicking the main test icon as shown below;
30+
31+
![Add Thread Group](images/load-test-add-thread-group.png)
32+
33+
34+
35+
Then, set number of threads (users) to 500 and set Ramp-up period to 10. If you need to use a higher number of users, you can increase thread value but be sure to increase the user count in the previous CSV/Excel file we have created to the same number.
36+
37+
### CSV Data Set Config
38+
39+
Then, right click to thread group and add a CSV data set config as shown below;
40+
41+
![CSV Data Set Config](images/load-test-csv-data-set-config.png)
42+
43+
Click the created CSV Data Set Config item and select the file we created in the previous step by using file browser on "Filename" field. After that enter "**UserName,Password**" to the variable names field and set ignore first line field to **True**. By doing this, we will be able to access columns of the CSV file by using its column names.
44+
45+
Before proceeding further, if you want to be sure that JMeter reads our CSV file, you can add a "Debug Sampler" item right under the CSV Data Set Config item and run the test once. Debug Sampler will log the values of the CSV file under the JMeter Variables section.
46+
47+
### HTTP Request
48+
49+
Since we are going to test an endpoint on a web app, we need to make an HTTP request to that endpoint. To do that, create a "HTTP Request" item right under the CSV Data Set Config item.
50+
51+
It should be a **POST** request and it should make a request to ```https://localhost:44301/api/TokenAuth/Authenticate``` endpoint. If your app uses a different port, you can change this URL as you wish.
52+
53+
For each request we want JMeter to get the username & password pairs from the CSV file we selected before and sent those items to endpoint we defined. In order to do this, set BodyData of the HTTP Request as shown below;
54+
55+
````json
56+
{
57+
"userNameOrEmailAddress": "${UserName}",
58+
"password": "${Password}"
59+
}
60+
````
61+
62+
#### HTTP Header Manager
63+
64+
We also need to configure "Content-Type" header for our HTTP Request. To do this, add a "HTTP Header Manager" under the HTTP Request item and add a new item to its headers list with the key "**Content-Type**" and value "**application/json**".
65+
66+
Finally, our HTTP Request configuration should be like this;
67+
68+
![HTTP Request Configuration](images/load-test-http-request-config.png)
69+
70+
### Test Result
71+
72+
Finally, add "View Result Tree" which shows status for each request and "Summary Report" which shows a summary for the HTTP Requests.
73+
74+
Now, we are ready to execute the test. After executing the test, we can check each request and see its post data and result as shown below;
75+
76+
![Load Test Result 1](images/load-test-result-1.png)
77+
78+
Or, we can check overall result of the test as shown below;
79+
80+
![Load Test Result 2](images/load-test-result-2.png)
81+
82+
By following a similar approach, we can test other endpoints of our app. If the endpoint is an authenticated endpoint, we should get a token from Authenticate endpoint we tested above, store it in JMeter and send with the request for the endpoint we want to test. This can be the topic of another article.
68 KB
Binary file not shown.

0 commit comments

Comments
 (0)