Last active
September 10, 2015 22:15
-
-
Save rdegges/3467ea8ef592111ec7c2 to your computer and use it in GitHub Desktop.
Load test.
This file contains hidden or 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 test is meant to test out Scenario 1: a lot of users are concurrently | |
# creating accounts and then logging into a web service with Stormpath. | |
# | |
# This script will create 1,000 users total before exiting. This script should | |
# be launched as many concurrent times as you want to emulate production | |
# traffic. | |
# | |
# INSTALL: | |
# To install this script, you need to have pip (for python) installed. Then run: | |
# | |
# $ pip install -U stormpath | |
# | |
# USAGE: | |
# Create a bash script called loadtest.sh in your current directory. Put the following | |
# code inside of it: | |
# | |
# python test.py & | |
# | |
# TESTING: | |
# | |
# Finally, to test everything out, you'll need to run the following command: | |
# | |
# $ for i in $(seq 0 200); do bash loadtest.sh; done | |
# | |
# Use the appropriate number of concurrency in the settings above, to esnure you run the | |
# script the appropriate amount of times. | |
# | |
# DEBUGGING: | |
# | |
# While the script is running, if you'd like to check to see if any processes have crashed | |
# due to 5XX errors from Stormpath, you can do the following: | |
# | |
# $ watch -n 10 'ps aux | grep python | wc -l' | |
# | |
# If that number drops, you know processes have crashed. | |
from uuid import uuid4 | |
from stormpath.client import Client | |
STORMPATH_API_KEY_ID = 'xxx' | |
STORMPATH_API_KEY_SECRET = 'yyy' | |
STORMPATH_URL = 'https://api.stormpath.com/v1' | |
TOTAL_USERS = 1000 | |
PASSWORD = uuid4().hex + uuid4().hex.upper() + '!' | |
client = Client(id=STORMPATH_API_KEY_ID, secret=STORMPATH_API_KEY_SECRET, base_url=STORMPATH_URL) | |
try: | |
application = client.applications.create({'name': 'scenario_1'}, create_directory=True) | |
except: | |
application = client.applications.search({'name': 'scenario_1'})[0] | |
try: | |
group = application.groups.create({'name': 'subscribers'}) | |
except: | |
group = application.groups.search({'name': 'subscribers'})[0] | |
for i in xrange(0, TOTAL_USERS): | |
email = uuid4().hex + '@test.com' | |
application.accounts.create({ | |
'given_name': 'test', | |
'surname': 'test', | |
'email': email, | |
'password': PASSWORD, | |
}) | |
print 'Account created:', email | |
account = application.authenticate_account(email, PASSWORD).account | |
print 'Authenticated account:', email | |
account.add_group(group) | |
print 'Added account to group:', group.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment