summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThais Siqueira <thais.siqueira@gmail.com>2016-03-11 10:57:34 -0300
committerThais Siqueira <thais.siqueira@gmail.com>2016-03-11 10:57:34 -0300
commit0313e643e30cfe202a100a0b69e7ff3c3875fff5 (patch)
tree208f5e6a4e9829f0f6abbc88ef2e48e3dc98e329
parent62ff59cbbb2aa4c4af378b6d0fc9dd853c8867e3 (diff)
Update locust test to run after xsrf token implementation.
- Adds port 8089 to vagrant file to be able to run inside vm. - Update requests version to 2.4.1, the minimum required version by locust. - Adds the xsrf token on locust post request headers. Issue #213
-rw-r--r--Vagrantfile1
-rw-r--r--service/requirements.txt2
-rw-r--r--service/test/load/locustfile.py21
3 files changed, 16 insertions, 8 deletions
diff --git a/Vagrantfile b/Vagrantfile
index ba925079..828382b9 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -30,5 +30,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider "virtualbox" do |v, override|
v.memory = 1024
override.vm.network :forwarded_port, guest: 3333, host: 3333 # do NOT add host_ip in this line. It is not necessary
+ override.vm.network :forwarded_port, guest: 8089, host: 8089
end
end
diff --git a/service/requirements.txt b/service/requirements.txt
index 95a0f4f8..7c9ee87c 100644
--- a/service/requirements.txt
+++ b/service/requirements.txt
@@ -4,7 +4,7 @@ https://launchpad.net/dirspec/stable-13-10/13.10/+download/dirspec-13.10.tar.gz
--allow-external dirspec --allow-unverified dirspec
https://launchpad.net/u1db/stable-13-10/13.10/+download/u1db-13.10.tar.bz2
pyasn1==0.1.8
-requests==2.0.0
+requests==2.4.1
srp==1.0.4
whoosh==2.5.7
pycryptopp
diff --git a/service/test/load/locustfile.py b/service/test/load/locustfile.py
index 68e39433..23142eee 100644
--- a/service/test/load/locustfile.py
+++ b/service/test/load/locustfile.py
@@ -1,6 +1,5 @@
import os
import json
-import time
from random import randint
from leap.auth import SRPAuth
@@ -11,7 +10,7 @@ from pixelated.resources.login_resource import LoginResource
LEAP_PROVIDER = os.environ.get('LEAP_PROVIDER', 'dev.pixelated-project.org')
LEAP_SERVER_HOST = os.environ.get('LEAP_SERVER_HOST', 'https://api.%s:4430' % LEAP_PROVIDER)
LEAP_VERIFY_CERTIFICATE = os.environ.get('LEAP_VERIFY_CERTIFICATE', '~/.leap/ca.crt')
-MAX_NUMBER_USER = os.environ.get('MAX_NUMBER_USER', 10000)
+MAX_NUMBER_USER = os.environ.get('MAX_NUMBER_USER', 100)
INVITES_FILENAME = os.environ.get('INVITES_FILENAME', '/tmp/invite_codes.txt')
INVITES_ENABLED = os.environ.get('INVITES_ENABLED', 'true') == 'true'
@@ -23,6 +22,10 @@ def load_invite_from_number(number):
class UserBehavior(TaskSet):
+ def __init__(self, *args, **kwargs):
+ super(UserBehavior, self).__init__(*args, **kwargs)
+ self.cookies = {}
+
def on_start(self):
""" on_start is called when a Locust start before any task is scheduled """
self.login()
@@ -40,9 +43,11 @@ class UserBehavior(TaskSet):
def login(self):
number = randint(1, int(MAX_NUMBER_USER))
username, password = self._get_or_create_user(number)
- self.client.post("/%s" % LoginResource.BASE_URL, {"username": username, "password": password})
+ response = self.client.post("/%s" % LoginResource.BASE_URL, {"username": username, "password": password})
+ self.cookies.update(response.cookies.get_dict())
+ resp = self.client.get("/")
+ self.cookies.update(resp.cookies.get_dict())
self.username = username
- time.sleep(5)
@task(1)
def index(self):
@@ -56,7 +61,9 @@ class UserBehavior(TaskSet):
def send_mail(self):
payload = {"tags": ["drafts"], "body": "some text lorem ipsum", "attachments": [], "ident": "",
"header": {"to": ["%s@%s" % (self.username, LEAP_PROVIDER)], "cc": [], "bcc": [], "subject": "load testing"}}
- with self.client.post('/mails', json=payload, catch_response=True) as email_response:
+ self.cookies.update(self.client.get("/").cookies.get_dict())
+ print(self.cookies)
+ with self.client.post('/mails', json=payload, catch_response=True, cookies=self.cookies, headers={'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN':self.cookies['XSRF-TOKEN']}) as email_response:
if email_response.status_code == 201:
email_id = json.loads(email_response.content)['ident']
print email_id
@@ -66,10 +73,10 @@ class UserBehavior(TaskSet):
def delete_mail(self, ident):
payload = {"idents": [ident]}
- self.client.post('/mails/delete', json=payload)
+ self.client.post('/mails/delete', json=payload, cookies=self.cookies, headers={'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN':self.cookies['XSRF-TOKEN']})
class WebsiteUser(HttpLocust):
task_set = UserBehavior
- min_wait = 3000
+ min_wait = 5000
max_wait = 15000