Skip to content

Commit

Permalink
Update to Python 3.12, closes #156
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Dec 22, 2023
1 parent 196108b commit 1bca19b
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

## Description

[Locust][0] is a distributed and scalable open-source library that helps you write effective
[Locust] is a distributed and scalable open-source library that helps you write effective
load tests in pure Python. This repository demonstrates a modular architecture that can work
as a template for quickly building a scalable stress testing pipeline with Locust.

## Locust terminology

If you're unfamiliar with the terminologies and the generic workflow of writing stress-tests
with Locust, then I recommend going through the official [documentation][1] first. With that
out of the way, let's rehash a few terminologies that comes up in this context quite often:
If you're unfamiliar with the terminologies and the general workflow of stress testing with
Locust, then I recommend going through the official [documentation] first. With that out
of the way, let's rehash a few terminologies that comes up in this context quite often:

**Task:** In Locust, a [Task][2] is the smallest unit of a test suite. Usually, it means,
**Task:** In Locust, a [Task] is the smallest unit of a test suite. Usually, it means,
any function or method that is decorated with the `@task` decorator.

**TaskSet:** A [TaskSet][3] is a class that establishes a contextual boundary between
**TaskSet:** A [TaskSet] is a class that establishes a contextual boundary between
different groups of Tasks. You can essentially group multiple similar Tasks inside a
TaskSet. Then you use the TaskSets from your User class.

**User:** In Locust, a [User][4] is a class that executes the tests either by directly
**User:** In Locust, a [User] is a class that executes the tests either by directly
calling the Task methods or via using TaskSets.

**_In more complex cases, the tests can further be organized by arranging them in multiple
Expand All @@ -32,14 +32,14 @@ separate test modules to achieve better modularity._**

## Target API

Here, we're using [Rapid API's][5] currency-exchange [API][6] to showcase the load testing
Here, we're using [Rapid API]'s currency-exchange [API] to showcase the load testing
procedure. The API converts one currency to another using the current exchange rate.

### API anatomy

It takes three parameters in its query string:

```
```txt
1. q : str - quantity
2. from : str - currency to convert from
3. to : str - currency to convert to
Expand All @@ -49,7 +49,7 @@ And returns the converted value.

### Access the API

Sign up for a Rapid API [account][7] and get your token. You can access the API via cURL
Sign up for a Rapid API [account] and get your token. You can access the API via cURL
like (You need to provide your API token in the header):

```sh
Expand All @@ -65,7 +65,7 @@ The response will look like this:
84.91925⏎
```

Or, you might want to access it via Python. You can do so using the [HTTPx][8] library like
Or, you might want to access it via Python. You can do so using the [HTTPx] library like
this:

```python
Expand Down Expand Up @@ -117,9 +117,8 @@ reside in the `setup.py` file.
The load test modules reside in the **`locustfiles`** directory. Test modules import and use
the functions in the `setup.py` file before executing each test.

In the `locustfiles` directory, currently, there are only two load test modules—
`bdt_convert.py` and `rs_convert.py`. You can name your test modules whatever you want and
the load testing classes and functions should reside here.
In the `locustfiles` folder, currently, there are only two load test modules:
`bdt_convert.py` and `rs_convert.py`. You can name your test modules whatever you want as long as the load testing classes and functions reside here.

- [bdt_convert.py](src/locustfiles/bdt_convert.py): This module houses a single TaskSet
named `BDTConvert` that has two Tasks—`usd_to_bdt` and `bdt_to_usd`. The first Task
Expand All @@ -135,7 +134,7 @@ the load testing classes and functions should reside here.

- [locustfile.py](src/locustfile.py): This file works as the entrypoint of the workflow.
It imports the TaskSets from the `bdt_convert` and `usd_convert` modules and creates a
[HttpUser][9] that will execute the tasks.
[HttpUser] that will execute the tasks.

### [locust.conf](src/locust.conf)

Expand All @@ -144,7 +143,7 @@ _workers_, _number of simulated users_, _spawn rate_, etc.

## Run the stress tests locally

- Make sure you have the latest version of [docker][10] and docker-compose installed on
- Make sure you have the latest version of [docker] and docker-compose installed on
your machine.

- Clone this repository and go to the root directory.
Expand All @@ -164,15 +163,15 @@ _workers_, _number of simulated users_, _spawn rate_, etc.
docker compose up -d --scale worker 2
```

- To access the Locust GUI, go to [http://localhost:8089/][11] on your browser. You'll be
- To access the Locust GUI, go to [http://localhost:8089/] on your browser. You'll be
greeted by a screen like below. You should see that the fields of the form are already
filled in since Locust pulls the values from the `locust.conf` file:
![locust signin][12]
![locust-signin]
- Once you've pressed the _start swarming_ button, you'll be taken to the following page:
![Screenshot from 2020-09-05 03-12-25][13]
![locust-dashboard]
- You can start, stop and control your tests from there.
Expand All @@ -181,19 +180,19 @@ _workers_, _number of simulated users_, _spawn rate_, etc.
This dockerized application is production-ready. However, you shouldn't expose your
environment file (.env) in production. Here, it was done only for demonstration purposes.

[0]: https://locust.io/
[1]: https://docs.locust.io/en/stable/
[2]: https://docs.locust.io/en/stable/writing-a-locustfile.html#tasks
[3]: https://docs.locust.io/en/stable/writing-a-locustfile.html#tasksets
[4]: https://docs.locust.io/en/stable/writing-a-locustfile.html#user-class
[5]: https://rapidapi.com/
[6]: https://rapidapi.com/fyhao/api/currency-exchange
[7]: https://rapidapi.com/signup
[8]: https://github.com/encode/httpx
[9]: https://docs.locust.io/en/stable/writing-a-locustfile.html#making-http-requests
[10]: https://www.docker.com/
[11]: http://localhost:8089/
[12]:
[locust]: https://locust.io/
[documentation]: https://docs.locust.io/en/stable/
[task]: https://docs.locust.io/en/stable/writing-a-locustfile.html#tasks
[taskset]: https://docs.locust.io/en/stable/writing-a-locustfile.html#tasksets
[user]: https://docs.locust.io/en/stable/writing-a-locustfile.html#user-class
[rapid api]: https://rapidapi.com/
[api]: https://rapidapi.com/fyhao/api/currency-exchange
[account]: https://rapidapi.com/signup
[httpx]: https://github.com/encode/httpx
[httpuser]: https://docs.locust.io/en/stable/writing-a-locustfile.html#making-http-requests
[docker]: https://www.docker.com/
[http://localhost:8089/]: http://localhost:8089/
[locust-signin]:
https://user-images.githubusercontent.com/30027932/92285103-51988580-ef25-11ea-9155-c9d3f5dcaf42.png
[13]:
[locust-dashboard]:
https://user-images.githubusercontent.com/30027932/92285284-b94ed080-ef25-11ea-9f91-3f972fd844f1.png

0 comments on commit 1bca19b

Please sign in to comment.