From 5dd5d764de52e08b2da238aea5c86c9bc20f3737 Mon Sep 17 00:00:00 2001 From: NavaL Date: Tue, 2 Feb 2016 13:58:33 +0100 Subject: WIP --- service/pixelated/resources/mails_resource.py | 2 +- service/test/load/locustfile.py | 66 +++++++++++++++++++++++++++ service/test_requirements.txt | 1 + 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 service/test/load/locustfile.py (limited to 'service') diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index c81cbd3b..5de707d7 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -199,7 +199,7 @@ class MailsResource(BaseResource): with_attachment_content = yield self._fetch_attachment_contents(content_dict, _mail_service) sent_mail = yield _mail_service.send_mail(with_attachment_content) - respond_json_deferred(sent_mail.as_dict(), request) + respond_json_deferred(sent_mail.as_dict(), request, status_code=201) @defer.inlineCallbacks def _handle_put(self, request): diff --git a/service/test/load/locustfile.py b/service/test/load/locustfile.py new file mode 100644 index 00000000..e2dcd4bd --- /dev/null +++ b/service/test/load/locustfile.py @@ -0,0 +1,66 @@ +import os +import json +import time +from random import randint + +from leap.auth import SRPAuth +from leap.exceptions import SRPAuthenticationError +from locust import HttpLocust, TaskSet, task +from pixelated.resources.login_resource import LoginResource + +LEAP_SERVER_HOST = os.environ.get('LEAP_SERVER_HOST', 'https://api.dev.pixelated-project.org:4430') +LEAP_VERIFY_CERTIFICATE = os.environ.get('LEAP_VERIFY_CERTIFICATE', '~/.leap/ca.crt') +MAX_NUMBER_USER = os.environ.get('MAX_NUMBER_USER', 10000) + + +class UserBehavior(TaskSet): + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + self.login() + + def _get_or_create_user(self, number): + srp_auth = SRPAuth(LEAP_SERVER_HOST, os.path.expanduser(LEAP_VERIFY_CERTIFICATE)) + # username, password = 'loadtest%d' % number, 'password_%d' % number + username, password = 'loadtest123', 'asdfasdf' + try: + srp_auth.authenticate(username, password) + except SRPAuthenticationError: + srp_auth.register(username, password) + return username, password + + def login(self): + number = randint(1, MAX_NUMBER_USER) + username, password = self._get_or_create_user(number) + self.client.post("/%s" % LoginResource.BASE_URL, {"username": username, "password": password}) + self.username = username + time.sleep(5) + + @task(1) + def index(self): + self.client.get("/") + + @task(2) + def mail_box(self): + self.client.get("/mails?q=tag:'inbox'&p=1&w=25") + + @task(3) + def send_mail(self): + payload = {"tags": ["drafts"], "body": "some text lorem ipsum", "attachments": [], "ident": "", + "header": {"to": ["%s@%s" % (self.username, LEAP_SERVER_HOST)], "cc": [], "bcc": [], "subject": "load testing"}} + with self.client.post('/mails', json=payload, catch_response=True) as email_response: + if email_response.status_code == 201: + email_id = json.loads(email_response.content)['ident'] + print email_id + self.delete_mail(email_id) + else: + email_response.failure('Error: email not Sent, status code: %s' % email_response.status_code) + + def delete_mail(self, ident): + payload = {"idents": [ident]} + self.client.post('/mails/delete', json=payload) + + +class WebsiteUser(HttpLocust): + task_set = UserBehavior + min_wait = 3000 + max_wait = 15000 diff --git a/service/test_requirements.txt b/service/test_requirements.txt index e53c1ad7..c1d12c78 100644 --- a/service/test_requirements.txt +++ b/service/test_requirements.txt @@ -10,3 +10,4 @@ tempdir==0.6 coverage crochet==1.4.0 poster==0.8.1 +locust \ No newline at end of file -- cgit v1.2.3 From 6d809fa4abdb824cb47455e057dfc8c344641474 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 2 Feb 2016 12:56:30 -0300 Subject: load test now using invites pairing with NavaL --- service/test/load/locustfile.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'service') diff --git a/service/test/load/locustfile.py b/service/test/load/locustfile.py index e2dcd4bd..7aca10e5 100644 --- a/service/test/load/locustfile.py +++ b/service/test/load/locustfile.py @@ -8,9 +8,17 @@ from leap.exceptions import SRPAuthenticationError from locust import HttpLocust, TaskSet, task from pixelated.resources.login_resource import LoginResource -LEAP_SERVER_HOST = os.environ.get('LEAP_SERVER_HOST', 'https://api.dev.pixelated-project.org:4430') +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) +INVITES_FILENAME = os.environ.get('INVITES_FILENAME', '/tmp/invite_codes.txt') + + +def load_invite_from_number(number): + with open(INVITES_FILENAME) as invites_file: + lines = invites_file.readlines() + return lines[number].strip() class UserBehavior(TaskSet): @@ -20,16 +28,16 @@ class UserBehavior(TaskSet): def _get_or_create_user(self, number): srp_auth = SRPAuth(LEAP_SERVER_HOST, os.path.expanduser(LEAP_VERIFY_CERTIFICATE)) - # username, password = 'loadtest%d' % number, 'password_%d' % number - username, password = 'loadtest123', 'asdfasdf' + username, password = ('loadtest%d' % number), ('password_%d' % number) +# username, password = 'loadtest123', 'asdfasdf' try: srp_auth.authenticate(username, password) except SRPAuthenticationError: - srp_auth.register(username, password) + srp_auth.register(username, password, load_invite_from_number(number)) return username, password def login(self): - number = randint(1, MAX_NUMBER_USER) + 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}) self.username = username @@ -46,7 +54,7 @@ class UserBehavior(TaskSet): @task(3) def send_mail(self): payload = {"tags": ["drafts"], "body": "some text lorem ipsum", "attachments": [], "ident": "", - "header": {"to": ["%s@%s" % (self.username, LEAP_SERVER_HOST)], "cc": [], "bcc": [], "subject": "load testing"}} + "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: if email_response.status_code == 201: email_id = json.loads(email_response.content)['ident'] -- cgit v1.2.3