Skip to content

Commit

Permalink
test: ✅ add api rates limit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nutfdt committed Jan 7, 2025
1 parent 1ca8d86 commit bc994eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
run: IMAGE_TAG=${{ needs.build-backend.outputs.image_tag }} docker compose -f docker-compose.yml -f docker-compose.ci.yml up -d
- run: docker compose exec backend coverage run -m pytest
- run: docker compose exec backend coverage xml --ignore-errors
- run: docker compose exec backend locust -f tests/locustfile.py -t 5s --headless --H http://localhost:5000/api
- name: Produce the coverage report
uses: insightsengineering/coverage-action@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ numpy<3.0.0
# Dev
pytest==8.3.4
coverage==7.6.10
Faker==33.3.0
Faker==33.3.0
locust==2.32.5
6 changes: 6 additions & 0 deletions backend/tests/locust.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
locustfile = tests/locustfile.py
headless = true
host = http://localhost:5000/api
run-time = 5s
spawn-rate =
users = 60
18 changes: 18 additions & 0 deletions backend/tests/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import time

from locust import HttpUser, task


class TestLocust(HttpUser):
@task
def rate_limit_version(self):
self.client.get("/version")

@task
def test_upload(self):
with open("./tests/images/revolver.jpg", "rb") as f:
self.client.post(
"/upload",
files={"image": f},
data={"date": time.time()},
)

0 comments on commit bc994eb

Please sign in to comment.