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,7 +15,7 @@
# 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',
@ -26,31 +26,40 @@ products = [
'9SIQT8TOJO', '9SIQT8TOJO',
'L9ECAV7KIM', 'L9ECAV7KIM',
'LS4PSXUNUM', 'LS4PSXUNUM',
'OLJCESPC7Z'] 'OLJCESPC7Z'
]
def index(l): class MyUser(HttpUser):
wait_time = between(5, 15)
@task(1)
def index(l):
l.client.get("/") l.client.get("/")
def setCurrency(l): @task(2)
def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD'] currencies = ['EUR', 'USD', 'JPY', 'CAD']
l.client.post("/setCurrency", l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)}) {'currency_code': random.choice(currencies)})
def browseProduct(l): @task(10)
def browseProduct(l):
l.client.get("/product/" + random.choice(products)) l.client.get("/product/" + random.choice(products))
def viewCart(l): @task(3)
def viewCart(l):
l.client.get("/cart") l.client.get("/cart")
def addToCart(l): @task(2)
def addToCart(l):
product = random.choice(products) product = random.choice(products)
l.client.get("/product/" + product) l.client.get("/product/" + product)
l.client.post("/cart", { l.client.post("/cart", {
'product_id': product, 'product_id': product,
'quantity': random.choice([1,2,3,4,5,10])}) 'quantity': random.choice([1,2,3,4,5,10])})
def checkout(l): @task(1)
addToCart(l) def checkout(l):
l.client.post("/cart/checkout", { l.client.post("/cart/checkout", {
'email': 'someone@example.com', 'email': 'someone@example.com',
'street_address': '1600 Amphitheatre Parkway', 'street_address': '1600 Amphitheatre Parkway',
@ -64,18 +73,3 @@ def checkout(l):
'credit_card_cvv': '672', 'credit_card_cvv': '672',
}) })
class UserBehavior(TaskSet):
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)