From a0bc490dc985f88d8a7f9a835e6cd202e82cc760 Mon Sep 17 00:00:00 2001 From: Patrick Maia Date: Fri, 12 Dec 2014 16:20:12 +0000 Subject: Card #168 - introduces performance tests for contacts controller --- service/test/perf/contacts/Contacts.conf | 33 +++++++++++++++ service/test/perf/contacts/__init__.py | 15 +++++++ service/test/perf/contacts/run | 26 ++++++++++++ service/test/perf/contacts/test_Contacts.py | 49 ++++++++++++++++++++++ .../test/support/integration/app_test_client.py | 4 +- service/test/support/integration/model.py | 12 ++++++ 6 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 service/test/perf/contacts/Contacts.conf create mode 100644 service/test/perf/contacts/__init__.py create mode 100755 service/test/perf/contacts/run create mode 100644 service/test/perf/contacts/test_Contacts.py (limited to 'service') diff --git a/service/test/perf/contacts/Contacts.conf b/service/test/perf/contacts/Contacts.conf new file mode 100644 index 00000000..e734d782 --- /dev/null +++ b/service/test/perf/contacts/Contacts.conf @@ -0,0 +1,33 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + +[main] +title=Contacts +description=Testing fetching contacts +url=http://localhost:4567/contacts?q=rec +nb_time=20 + +[bench] +cycles = 1:3:6 +duration = 10 +startup_delay = 0.01 +sleep_time = 0.01 +cycle_time = 1 +log_to = +log_path = results/contacts-bench.log +result_path = results/contacts-bench.xml +sleep_time_min = 0 +sleep_time_max = 0.5 diff --git a/service/test/perf/contacts/__init__.py b/service/test/perf/contacts/__init__.py new file mode 100644 index 00000000..2756a319 --- /dev/null +++ b/service/test/perf/contacts/__init__.py @@ -0,0 +1,15 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . diff --git a/service/test/perf/contacts/run b/service/test/perf/contacts/run new file mode 100755 index 00000000..958bb519 --- /dev/null +++ b/service/test/perf/contacts/run @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + +if ! which gnuplot +then + echo "You must install gnuplot to run perf tests" + exit 1 +fi + +mkdir -p results +fl-run-bench test_Contacts.py Contacts.test_contacts +LC_ALL=en_US.ascii fl-build-report --html results/contacts-bench.xml diff --git a/service/test/perf/contacts/test_Contacts.py b/service/test/perf/contacts/test_Contacts.py new file mode 100644 index 00000000..8bfb898d --- /dev/null +++ b/service/test/perf/contacts/test_Contacts.py @@ -0,0 +1,49 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +import unittest + +from funkload.FunkLoadTestCase import FunkLoadTestCase +from test.support.integration import AppTestClient + + +class Contacts(FunkLoadTestCase): + + def setUpBench(self): + client = AppTestClient() + + # setup data + client.add_multiple_to_mailbox(10, 'INBOX', to='to@inbox.com', cc='cc@inbox.com', bcc='bcc@inbox.com') + client.add_multiple_to_mailbox(10, 'TRASH', to='to@trash.com', cc='cc@trash.com', bcc='bcc@trash.com') + client.add_multiple_to_mailbox(10, 'DRAFTS', to='to@drafts.com', cc='cc@drafts.com', bcc='bcc@drafts.com') + + self.call_to_terminate = client.run_on_a_thread(logfile='results/app.log') + + def tearDownBench(self): + self.call_to_terminate() + + def setUp(self): + """Setting up test.""" + self.server_url = self.conf_get('main', 'url') + + def test_contacts(self): + server_url = self.server_url + nb_time = self.conf_getInt('main', 'nb_time') + + for i in range(nb_time): + self.get(server_url, description='Get Contacts') + +if __name__ in ('main', '__main__'): + unittest.main() diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index 2a35a89f..82b34d69 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -122,10 +122,10 @@ class AppTestClient: mail.update_tags(input_mail.tags) self.search_engine.index_mail(mail) - def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[]): + def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[], to='recipient@to.com', cc='recipient@cc.com', bcc='recipient@bcc.com'): mails = [] for _ in range(num): - input_mail = MailBuilder().with_status(flags).with_tags(tags).build_input_mail() + input_mail = MailBuilder().with_status(flags).with_tags(tags).with_to(to).with_cc(cc).with_bcc(bcc).build_input_mail() mail = self.mailboxes._create_or_get(mailbox).add(input_mail) mails.append(mail) mail.update_tags(input_mail.tags) diff --git a/service/test/support/integration/model.py b/service/test/support/integration/model.py index 79552dad..e05d74bb 100644 --- a/service/test/support/integration/model.py +++ b/service/test/support/integration/model.py @@ -44,6 +44,18 @@ class MailBuilder: self.mail['header']['subject'] = subject return self + def with_to(self, to): + self.mail['header']['to'] = to + return self + + def with_cc(self, cc): + self.mail['header']['cc'] = cc + return self + + def with_bcc(self, bcc): + self.mail['header']['bcc'] = bcc + return self + def with_status(self, flags): for status in Status.from_flags(flags): self.mail['status'].append(status) -- cgit v1.2.3