This commit is contained in:
Luke Crouch 2018-08-28 13:52:10 -05:00
Родитель dd49eddb0b
Коммит aee74dbfee
6 изменённых файлов: 122 добавлений и 60 удалений

Просмотреть файл

@ -16,13 +16,12 @@ $ pip install -r requirements.txt
## Running the load tests
To run the exquisite load tests, simply run <kbd>$ ./run.sh</kbd>.
To modify the default settings, tweak the settings in ./molotov.env.
By default, the load tests will run for 180s (3 minutes), with 20 processes (each w/ 10 workers, for a total of 200 workers).
```ini
DURATION=180
PROCESSES=20
WORKERS=10
Dev server:
```sh
locust --host=https://fx-breach-alerts.herokuapp.com
```
Stage server (Note: ask breach-alerts@mozilla.com first):
```sh
locust --host=https://blurts-server.stage.mozaws.net/
```

Просмотреть файл

@ -1,24 +0,0 @@
from os import getenv
from molotov import scenario
SERVER_URL = getenv('SERVER_URL', 'https://fx-breach-alerts.herokuapp.com')
HOMEPAGE_URL = SERVER_URL
SCAN_URL = '{}/scan'.format(SERVER_URL)
# This hash is for test@example.com (via `node scripts/make-sha1-hashes.js`)
TEST_EMAIL_HASH = '567159d622ffbb50b11b0efd307be358624a26ee'
WEIGHT_HOMEPAGE = int(getenv('WEIGHT_HOMEPAGE', 0))
WEIGHT_SCAN = int(getenv('WEIGHT_SCAN', 0))
@scenario(weight=WEIGHT_HOMEPAGE)
async def homepage_test(session):
async with session.get(HOMEPAGE_URL) as resp:
assert resp.status == 200
@scenario(weight=WEIGHT_SCAN)
async def scan_test(session):
async with session.post(SCAN_URL, data={'emailHash': TEST_EMAIL_HASH}) as resp:
assert resp.status == 200

113
loadtests/locustfile.py Normal file
Просмотреть файл

@ -0,0 +1,113 @@
from itertools import takewhile
import hashlib
import random
import string
from locust import HttpLocust, TaskSet, task
TEST_SIGNUP_ADDRESSES = [
'success@simulator.amazonses.com',
'bounce@simulator.amazonses.com',
'ooto@simulator.amazonses.com',
'complaint@simulator.amazonses.com',
'suppressionlist@simulator.amazonses.com',
]
TEST_SIGNUP_ADDRESSES_WEIGHTS = [
0.9,
0.06,
0.02,
0.01,
0.01
]
def accumulate(iterator):
current = 0
for value in iterator:
current += value
yield current
def weightedChoice(weights, objects):
limit = random.random()
return objects[
sum(takewhile(bool, (value < limit for value in accumulate(weights))))
]
def get_test_signup_email_address():
return weightedChoice(TEST_SIGNUP_ADDRESSES_WEIGHTS, TEST_SIGNUP_ADDRESSES)
def generate_random_email_address():
name = ''.join(random.choices(string.ascii_letters + string.digits, k=20))
host = ''.join(random.choices(string.ascii_letters + string.digits, k=20))
tld = ''.join(random.choice(['com', 'org', 'edu']))
email_string = "%s@%s.%s" % (name, host, tld)
return email_string
@task
def visit_home(l):
l.client.get("/")
@task
def scan(l):
email_address = generate_random_email_address()
email_hash = hashlib.sha1(email_address.encode('utf-8')).hexdigest()
l.client.post("/scan", {"emailHash": email_hash})
@task
def sign_up(l):
email = get_test_signup_email_address()
l.client.post("/user/add", json={"email": email})
@task
def verify(l):
l.client.get("/user/verify?token=5a66c262-9bed-4893-b53d-3759cbe3d564")
class WebsiteBounce(TaskSet):
tasks = {visit_home: 1}
class Scan(TaskSet):
tasks = {visit_home: 1, scan: 1}
class Signup(TaskSet):
tasks = {visit_home: 1, scan: 1, sign_up: 1}
class Verify(TaskSet):
tasks = {visit_home: 1, scan: 1, sign_up: 1, verify: 1}
class WebsiteBouncer(HttpLocust):
task_set = WebsiteBounce
min_wait = 2000
max_wait = 15000
class Scanner(HttpLocust):
task_set = Scan
min_wait = 2000
max_wait = 15000
class Subscriber(HttpLocust):
task_set = Signup
min_wait = 2000
max_wait = 15000
class Verifier(HttpLocust):
task_set = Verify
min_wait = 2000
max_wait = 15000

Просмотреть файл

@ -1,14 +0,0 @@
PROJECT=FirefoxMonitor
SERVER_URL=https://fx-breach-alerts.herokuapp.com
VERBOSE=-v
TEST_MODULE=loadtest.py
RUN_DELAY=0
DURATION=180
PROCESSES=20
WORKERS=10
export WEIGHT_HOMEPAGE=1
export WEIGHT_SCAN=1

Просмотреть файл

@ -1 +1 @@
molotov
locustio==0.8.1

Просмотреть файл

@ -1,12 +0,0 @@
source molotov.env
echo "WEIGHT_HOMEPAGE=$WEIGHT_HOMEPAGE"
echo "WEIGHT_SCAN=$WEIGHT_SCAN"
echo "DURATION=$DURATION"
echo "PROCESSES=$PROCESSES"
echo "WORKERS=$WORKERS"
echo "DELAY=$RUN_DELAY"
WEIGHT_HOMEPAGE=$WEIGHT_HOMEPAGE \
WEIGHT_SCAN=$WEIGHT_SCAN \
time molotov "$VERBOSE" -d "$DURATION" -p "$PROCESSES" -w "$WORKERS" --delay "$RUN_DELAY" loadtest.py