fix: update locust files for current locust version

This commit is contained in:
jorge.gonzalez 2020-07-15 10:55:40 +02:00
parent fccaff8885
commit 73ea4bc017
2 changed files with 49 additions and 55 deletions

View file

@ -32,4 +32,4 @@ if test $STATUSCODE -ne 200; then
fi fi
# else, run loadgen # else, run loadgen
locust --host="http://${FRONTEND_ADDR}" --no-web -c "${USERS:-10}" 2>&1 locust --host="http://${FRONTEND_ADDR}" --headless --users "${USERS:-10}" 2>&1

View file

@ -15,67 +15,61 @@
# limitations under the License. # limitations under the License.
import random import random
from locust import HttpLocust, TaskSet, between from locust import HttpUser, between, task
products = [ products = [
'0PUK6V6EV0', '0PUK6V6EV0',
'1YMWWN1N4O', '1YMWWN1N4O',
'2ZYFJ3GM2N', '2ZYFJ3GM2N',
'66VCHSJNUP', '66VCHSJNUP',
'6E92ZMYYFZ', '6E92ZMYYFZ',
'9SIQT8TOJO', '9SIQT8TOJO',
'L9ECAV7KIM', 'L9ECAV7KIM',
'LS4PSXUNUM', 'LS4PSXUNUM',
'OLJCESPC7Z'] 'OLJCESPC7Z'
]
def index(l): class MyUser(HttpUser):
l.client.get("/") wait_time = between(5, 15)
def setCurrency(l): @task(1)
currencies = ['EUR', 'USD', 'JPY', 'CAD'] def index(l):
l.client.post("/setCurrency", l.client.get("/")
{'currency_code': random.choice(currencies)})
def browseProduct(l): @task(2)
l.client.get("/product/" + random.choice(products)) def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD']
l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)})
def viewCart(l): @task(10)
l.client.get("/cart") def browseProduct(l):
l.client.get("/product/" + random.choice(products))
def addToCart(l): @task(3)
product = random.choice(products) def viewCart(l):
l.client.get("/product/" + product) l.client.get("/cart")
l.client.post("/cart", {
'product_id': product,
'quantity': random.choice([1,2,3,4,5,10])})
def checkout(l): @task(2)
addToCart(l) def addToCart(l):
l.client.post("/cart/checkout", { product = random.choice(products)
'email': 'someone@example.com', l.client.get("/product/" + product)
'street_address': '1600 Amphitheatre Parkway', l.client.post("/cart", {
'zip_code': '94043', 'product_id': product,
'city': 'Mountain View', 'quantity': random.choice([1,2,3,4,5,10])})
'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',
})
class UserBehavior(TaskSet): @task(1)
def checkout(l):
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',
})
def on_start(self):
index(self)
tasks = {index: 1,
setCurrency: 2,
browseProduct: 10,
addToCart: 2,
viewCart: 3,
checkout: 1}
class WebsiteUser(HttpLocust):
task_set = UserBehavior
wait_time = between(1, 10)