-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[loadgenerator] - rewrite for new frontend and feature flags (#290)
* loadgenerator rewrite * remove set_currency from load generator * add multi item checkout
- Loading branch information
Showing
2 changed files
with
213 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ | |
# limitations under the License. | ||
|
||
import random | ||
from locust import HttpUser, TaskSet, between | ||
import uuid | ||
from locust import HttpUser, task, between | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.sdk.trace import TracerProvider | ||
|
@@ -33,64 +34,222 @@ | |
URLLib3Instrumentor().instrument() | ||
|
||
products = [ | ||
'0PUK6V6EV0', | ||
'1YMWWN1N4O', | ||
'2ZYFJ3GM2N', | ||
'66VCHSJNUP', | ||
'6E92ZMYYFZ', | ||
'9SIQT8TOJO', | ||
'L9ECAV7KIM', | ||
'LS4PSXUNUM', | ||
'OLJCESPC7Z'] | ||
"0PUK6V6EV0", | ||
"1YMWWN1N4O", | ||
"2ZYFJ3GM2N", | ||
"66VCHSJNUP", | ||
"6E92ZMYYFZ", | ||
"9SIQT8TOJO", | ||
"L9ECAV7KIM", | ||
"LS4PSXUNUM", | ||
"OLJCESPC7Z" | ||
] | ||
|
||
def index(l): | ||
l.client.get("/") | ||
people = [ | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "1600 Amphitheatre Parkway", | ||
"zipCode": 94043, | ||
"city": "Mountain View", | ||
"state": "CA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4432-8015-6152-0454", | ||
"creditCardExpirationMonth": 1, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 672 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "One Microsoft Way", | ||
"zipCode": 98052, | ||
"city": "Redmond", | ||
"state": "WA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4532-4211-7434-1278", | ||
"creditCardExpirationMonth": 2, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 114 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "One Apple Park Way", | ||
"zipCode": 95014, | ||
"city": "Cupertino", | ||
"state": "CA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4532-6178-2799-1951", | ||
"creditCardExpirationMonth": 3, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 239 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "1 Hacker Way", | ||
"zipCode": 94025, | ||
"city": "Menlo Park", | ||
"state": "CA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4539-1103-5661-7083", | ||
"creditCardExpirationMonth": 4, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 784 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "410 Terry Ave N", | ||
"zipCode": 98109, | ||
"city": "Seattle", | ||
"state": "WA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4916-0816-6217-7968", | ||
"creditCardExpirationMonth": 5, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 397 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "100 Winchester Circle", | ||
"zipCode": 95032, | ||
"city": "Los Gatos", | ||
"state": "CA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4929-5431-0337-5647", | ||
"creditCardExpirationMonth": 6, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 793 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "150 Elgin St", | ||
"zipCode": 214, | ||
"city": "Ottawa", | ||
"state": "ON", | ||
"country": "Canada" | ||
}, | ||
"userCurrency": "CAD", | ||
"creditCard": { | ||
"creditCardNumber": "4763-1844-9699-8031", | ||
"creditCardExpirationMonth": 7, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 488 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "1355 Market St", | ||
"zipCode": 94103, | ||
"city": "San Francisco", | ||
"state": "CA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4929-6495-8333-3657", | ||
"creditCardExpirationMonth": 8, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 159 | ||
} | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"address": { | ||
"streetAddress": "2200 Mission College Blvd", | ||
"zipCode": 95054, | ||
"city": "Santa Clara", | ||
"state": "CA", | ||
"country": "United States" | ||
}, | ||
"userCurrency": "USD", | ||
"creditCard": { | ||
"creditCardNumber": "4485-4803-8707-3547", | ||
"creditCardExpirationMonth": 9, | ||
"creditCardExpirationYear": 2039, | ||
"creditCardCvv": 682 | ||
} | ||
} | ||
] | ||
|
||
def setCurrency(l): | ||
currencies = ['EUR', 'USD', 'JPY', 'CAD'] | ||
l.client.post("/setCurrency", | ||
{'currency_code': random.choice(currencies)}) | ||
|
||
def browseProduct(l): | ||
l.client.get("/product/" + random.choice(products)) | ||
class WebsiteUser(HttpUser): | ||
wait_time = between(1, 10) | ||
|
||
def viewCart(l): | ||
l.client.get("/cart") | ||
@task(1) | ||
def index(self): | ||
self.client.get("/") | ||
|
||
def addToCart(l): | ||
product = random.choice(products) | ||
l.client.get("/product/" + product) | ||
l.client.post("/cart", { | ||
'product_id': product, | ||
'quantity': random.choice([1,2,3,4,5,10])}) | ||
@task(10) | ||
def browse_product(self): | ||
self.client.get("/product/" + random.choice(products)) | ||
|
||
def checkout(l): | ||
addToCart(l) | ||
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', | ||
}) | ||
@task(3) | ||
def view_cart(self): | ||
self.client.get("/cart") | ||
|
||
class UserBehavior(TaskSet): | ||
@task(2) | ||
def add_to_cart(self, user=""): | ||
if user == "": | ||
user = str(uuid.uuid1()) | ||
product = random.choice(products) | ||
self.client.get("/product/" + product) | ||
cart_item = { | ||
"item": { | ||
"productId": product, | ||
"quantity": random.choice([1, 2, 3, 4, 5, 10]) | ||
}, | ||
"userId": user | ||
} | ||
self.client.post("/api/cart", json=cart_item) | ||
|
||
def on_start(self): | ||
index(self) | ||
@task(1) | ||
def checkout(self): | ||
# checkout call with an item added to cart | ||
user = str(uuid.uuid1()) | ||
self.add_to_cart(user=user) | ||
checkout_person = random.choice(people) | ||
checkout_person["userId"] = user | ||
self.client.post("/api/checkout", json=checkout_person) | ||
|
||
tasks = {index: 1, | ||
setCurrency: 2, | ||
browseProduct: 10, | ||
addToCart: 2, | ||
viewCart: 3, | ||
checkout: 1} | ||
@task(1) | ||
def checkout_multi(self): | ||
# checkout call which adds 2-4 different items to cart before checkout | ||
user = str(uuid.uuid1()) | ||
for i in range(random.choice([2, 3, 4])): | ||
self.add_to_cart(user=user) | ||
checkout_person = random.choice(people) | ||
checkout_person["userId"] = user | ||
self.client.post("/api/checkout", json=checkout_person) | ||
|
||
class WebsiteUser(HttpUser): | ||
tasks = [UserBehavior] | ||
wait_time = between(1, 10) | ||
def on_start(self): | ||
self.index() |