Should now actually work

This commit is contained in:
Elizabeth Byerly 2019-05-22 09:53:52 -04:00
parent 0b4f577240
commit 3a12c74af3
7 changed files with 37 additions and 21 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ pkg/
.idea
.skaffold-*.yaml
.kubernetes-manifests-*/
env/

View file

@ -31,9 +31,9 @@ spec:
initContainers:
- name: wait-frontend
image: alpine:3.6
command: ['sh', '-c', 'set -x; apk add --no-cache curl &&
until timeout -t 2 curl -f "http://${FRONTEND_ADDR}"; do
echo "waiting for http://${FRONTEND_ADDR}";
command: ['sh', '-c', 'set -x; apk add --no-cache curl &&
until timeout -t 2 curl -f "http://${FRONTEND_ADDR}"; do
echo "waiting for http://${FRONTEND_ADDR}";
sleep 2;
done;']
env:

View file

@ -14,4 +14,5 @@ FROM base
COPY --from=builder /install /usr/local
COPY . .
ENTRYPOINT ./loadgen.sh
ENTRYPOINT ["./loadgen.sh"]

View file

@ -18,10 +18,15 @@
set -e
trap "exit" TERM
if [[ -z "${FRONTEND_ADDR}" ]]; then
if [ -z "${FRONTEND_ADDR}" ]; then
echo >&2 "FRONTEND_ADDR not specified"
exit 1
fi
set -x
locust --host="http://${FRONTEND_ADDR}" --no-web -c "${USERS:-10}"
locust \
-f locustfile.py \
--host="http://${FRONTEND_ADDR}" \
--no-web \
-c "${USERS:-10}" \
-r 1

View file

@ -30,26 +30,32 @@ products = [
'LS4PSXUNUM',
'OLJCESPC7Z']
def index(l):
l.client.get("/")
def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD']
l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)})
{'currency_code': random.choice(currencies)})
def browseProduct(l):
l.client.get("/product/" + random.choice(products))
def viewCart(l):
l.client.get("/cart")
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])})
'quantity': random.choice([1, 2, 3, 4, 5, 10])})
def checkout(l):
addToCart(l)
@ -66,9 +72,17 @@ def checkout(l):
'credit_card_cvv': '672',
})
class UserBehavior(TaskSet):
min_wait = 1000
max_wait = 20000
min_wait = 500
max_wait = 1500
tasks = {index: 1,
setCurrency: 2,
browseProduct: 10,
addToCart: 2,
viewCart: 3,
checkout: 1}
def on_start(self):
index(self)
@ -83,14 +97,9 @@ class UserBehavior(TaskSet):
traffic_scaler = (traffic_scaler + 1) / 2.0
# Scale traffic between minimum and maximum wait times.
return self.max_wait + (self.min_wait - self.max_wait) * traffic_scaler
wait = self.max_wait + (self.min_wait - self.max_wait) * traffic_scaler
return round(wait)
tasks = {index: 1,
setCurrency: 2,
browseProduct: 10,
addToCart: 2,
viewCart: 3,
checkout: 1}
class WebsiteUser(HttpLocust):
task_set = UserBehavior

View file

@ -1 +1 @@
locustio==0.8.1
locustio==0.9.0

View file

@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt requirements.in
# pip-compile --output-file=requirements.txt requirements.in
#
certifi==2018.11.29 # via requests
chardet==3.0.4 # via requests
@ -13,9 +13,9 @@ greenlet==0.4.15 # via gevent
idna==2.8 # via requests
itsdangerous==1.1.0 # via flask
jinja2==2.10 # via flask
locustio==0.8.1
locustio==0.9.0
markupsafe==1.1.0 # via jinja2
msgpack-python==0.5.6 # via locustio
msgpack==0.6.1 # via locustio
pyzmq==17.0.0 # via locustio
requests==2.21.0 # via locustio
six==1.12.0 # via locustio