https://github.com/nikouu/one-class-load-tester
🏋️♂️ A really simple few lines of code to get a dirty load tester going. 🏋️♀️
https://github.com/nikouu/one-class-load-tester
csharp load-test load-testing
Last synced: about 1 year ago
JSON representation
🏋️♂️ A really simple few lines of code to get a dirty load tester going. 🏋️♀️
- Host: GitHub
- URL: https://github.com/nikouu/one-class-load-tester
- Owner: nikouu
- License: mit
- Created: 2023-01-19T04:46:28.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-20T03:20:30.000Z (over 3 years ago)
- Last Synced: 2025-04-06T08:08:51.689Z (about 1 year ago)
- Topics: csharp, load-test, load-testing
- Language: C#
- Homepage:
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# One Class Load Tester 💪
A really simple few lines of code to get a dirty load tester going. So easy in fact, it's a single class that could **just be copied over**. Meaning if you are unable to clone, or download an .exe, the copying is super simple.

## Where did this come from?
I needed a really quick and dirty load tester and I wasn't in a position to clone or download projects/libraries/software... So this thing was created 💀
## How does it work?
All the magic is in `LoadTestEngine.cs`.
The core concept is the "test group" and inside each group is each bunch of requests you're looking to fire at once. Plus a test group has what value of delay to wait before the next bunch of requests. For example, let's say you wanted to do 5 requests every 2 seconds. This is two test groups with five tasks in each, with the delay set to 2000ms.
See the example below for a more clear picture.
### public record TestGroup(List TestTasks, int PostTestDelay)
```csharp
public record TestGroup(List TestTasks, int PostTestDelay);
```
Where:
| Parameter | Usage |
| --------------- | ------------------------------------------------------------------------------ |
| `TestTasks` | All the request to be made per test group. A list of normal C# `Task` objects. |
| `PostTestDelay` | The delay in milliseconds before the next test group. |
Note: The final delay actually doesn't matter as the code will end after the delay value.
## Test Server
With this solution is a test server which is a simple minimal API project to help goes along with the default load testing project. Run both at the same time to see the console fill with requests.
## What about tokens, query strings, tokens, mTLS certificates?
With the raw `HttpClient` object sitting there, you should be able to quickly attach anything else you need in the same way you probably have done it in your normal project.
With limitations of `HttpClient` around things like headers, you may want to create an `HttpClient` object as per what you need and add it to `TestGroup` or create an object to represent TestTasks which has the `Task` and anything else you need to run your test for each run.