Skip to content

Commit

Permalink
feat: strengthen the load generator with fuzz input
Browse files Browse the repository at this point in the history
  • Loading branch information
Lincyaw committed Feb 27, 2024
1 parent cbfe712 commit 7878b9f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
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': '[email protected]',
'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.22.0
faker==23.2.1
16 changes: 13 additions & 3 deletions src/loadgenerator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
# pip-compile requirements.in
#
blinker==1.7.0
# via flask
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 All @@ -37,6 +39,8 @@ greenlet==3.0.3
# via gevent
idna==3.6
# via requests
importlib-metadata==7.0.1
# via flask
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand All @@ -51,21 +55,27 @@ msgpack==1.0.7
# via locust
psutil==5.9.8
# via locust
python-dateutil==2.8.2
# 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.0
# via requests
werkzeug==3.0.1
# via
# flask
# flask-login
# locust
zipp==3.17.0
# via importlib-metadata
zope-event==5.0
# via gevent
zope-interface==6.1
Expand Down

0 comments on commit 7878b9f

Please sign in to comment.