Created
March 15, 2019 11:50
-
-
Save AntonioArts/14c27e4974b896304151af5a87724579 to your computer and use it in GitHub Desktop.
locust-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
import os | |
import json | |
import jwt | |
import yaml | |
import random | |
import time | |
from urllib.parse import urlencode | |
from locust import HttpLocust, TaskSet, task | |
def encode_jwt(body): | |
base = { | |
'iss': 'barong', | |
'sub': 'session', | |
'aud': 'peatio', | |
'role': 'member', | |
'state': 'active', | |
'level': 3, | |
} | |
payload = { **base, **body } | |
return jwt.encode(payload, (os.environ['LOCUST_SECRET_KEY']).encode("UTF-8"), algorithm="RS256") | |
class UserBehavior(TaskSet): | |
@task(100) | |
def index(self): | |
now = round(time.time()) | |
rand_num = random.randint(1, 21) | |
body = { | |
'iat': now, | |
'exp': now + 5000, | |
'email': 'user' + str(rand_num) + '@gmail.com', | |
'uid': 'ID00000000' + str(rand_num), | |
'market': 'ethusd', | |
'side': random.choice(['buy', 'sell']), | |
'volume': '1', | |
'price': '1', | |
} | |
headers = { | |
'Authorization': 'Bearer ' + encode_jwt(body).decode('utf-8') | |
} | |
self.client.post('/api/v2/market/orders') | |
class WebsiteUser(HttpLocust): | |
task_set = UserBehavior | |
min_wait = 5000 | |
max_wait = 9000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment