Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: strengthen the load generator with fuzz input #2398

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import random
from locust import HttpUser, TaskSet, between
from faker import Faker
import datetime
fake = Faker()

products = [
'0PUK6V6EV0',
Expand All @@ -32,7 +35,7 @@ def index(l):
l.client.get("/")

def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD']
currencies = ['EUR', 'USD', 'JPY', 'CAD', 'GBP', 'TRY']
l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)})

Expand All @@ -47,22 +50,30 @@ def addToCart(l):
l.client.get("/product/" + product)
l.client.post("/cart", {
'product_id': product,
'quantity': random.choice([1,2,3,4,5,10])})
'quantity': random.randint(1,100)})

def empty_cart(l):
l.client.post('/cart/empty')

def checkout(l):
addToCart(l)
current_year = datetime.datetime.now().year+1
l.client.post("/cart/checkout", {
'email': 'someone@example.com',
'street_address': '1600 Amphitheatre Parkway',
'zip_code': '94043',
'city': 'Mountain View',
'state': 'CA',
'country': 'United States',
'credit_card_number': '4432-8015-6152-0454',
'credit_card_expiration_month': '1',
'credit_card_expiration_year': '2039',
'credit_card_cvv': '672',
'email': fake.email(),
'street_address': fake.street_address(),
'zip_code': fake.zipcode(),
'city': fake.city(),
'state': fake.state_abbr(),
'country': fake.country(),
'credit_card_number': fake.credit_card_number(card_type="visa"),
'credit_card_expiration_month': random.randint(1, 12),
'credit_card_expiration_year': random.randint(current_year, current_year + 70),
'credit_card_cvv': f"{random.randint(100, 999)}",
})

def logout(l):
l.client.get('/logout')


class UserBehavior(TaskSet):

Expand Down
1 change: 1 addition & 0 deletions src/loadgenerator/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
locust==2.24.0
faker==23.2.1
10 changes: 8 additions & 2 deletions src/loadgenerator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
Expand All @@ -18,6 +18,8 @@ click==8.1.7
# via flask
configargparse==1.7
# via locust
faker==23.2.1
# via -r requirements.in
flask==3.0.2
# via
# flask-cors
Expand Down Expand Up @@ -51,14 +53,18 @@ msgpack==1.0.8
# via locust
psutil==5.9.8
# via locust
python-dateutil==2.9.0.post0
# via faker
pyzmq==25.1.2
# via locust
requests==2.31.0
# via locust
roundrobin==0.0.4
# via locust
six==1.16.0
# via geventhttpclient
# via
# geventhttpclient
# python-dateutil
urllib3==2.2.1
# via requests
werkzeug==3.0.1
Expand Down
Loading