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 25, 2024
1 parent cbfe712 commit 2edbc92
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 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
3 changes: 2 additions & 1 deletion src/loadgenerator/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ zope-event==5.0
# via gevent
zope-interface==6.1
# via gevent

faker==23.2.1
# via faker
# The following packages are considered to be unsafe in a requirements file:
# setuptools

0 comments on commit 2edbc92

Please sign in to comment.