From b4b2a042910180907ef1883396bc7f18ac402df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 8 Oct 2018 14:09:42 +0000 Subject: [PATCH] [IMP] test_mass_mailing: add performance tests Purpose is to have some basis performance counters when sending a mailing on 100 records, with and without blacklist involved. It will serves as reference when working on mass mailing performance improvements in future tasks. This commit is linked to task ID 1889703 and PR #27526. --- addons/test_mass_mailing/tests/__init__.py | 1 + .../tests/test_performance.py | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 addons/test_mass_mailing/tests/test_performance.py diff --git a/addons/test_mass_mailing/tests/__init__.py b/addons/test_mass_mailing/tests/__init__.py index caed78c5432..4283fdd0861 100644 --- a/addons/test_mass_mailing/tests/__init__.py +++ b/addons/test_mass_mailing/tests/__init__.py @@ -7,3 +7,4 @@ from . import test_composer from . import test_mail_auto_blacklist from . import test_mail_channel from . import test_mass_mailing +from . import test_performance diff --git a/addons/test_mass_mailing/tests/test_performance.py b/addons/test_mass_mailing/tests/test_performance.py new file mode 100644 index 00000000000..b406474e224 --- /dev/null +++ b/addons/test_mass_mailing/tests/test_performance.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.test_mass_mailing.tests import common +from odoo.tests.common import users, warmup +from odoo.tests import tagged +from odoo.tools import mute_logger + + +@tagged('mail_performance') +class TestMassMailPerformance(common.MassMailingCase): + + def setUp(self): + super(TestMassMailPerformance, self).setUp() + values = [{ + 'name': 'Recipient %s' % x, + 'email_from': 'Recipient ' % x, + } for x in range(0, 50)] + self.mm_recs = self.env['mass.mail.test'].create(values) + + @users('__system__', 'marketing') + @warmup + @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + def test_send_mailing(self): + mailing = self.env['mail.mass_mailing'].create({ + 'name': 'Test', + 'body_html': '

Hello quuxUnsubscribe

', + 'reply_to_mode': 'email', + 'mailing_model_id': self.ref('test_mass_mailing.model_mass_mail_test'), + 'mailing_domain': [('id', 'in', self.mm_recs.ids)], + }) + + with self.assertQueryCount(__system__=2382, marketing=3038): + mailing.send_mail() + + self.assertEqual(mailing.sent, 50) + self.assertEqual(mailing.delivered, 50) + + +@tagged('mail_performance') +class TestMassMailBlPerformance(common.MassMailingCase): + + def setUp(self): + """ In this setup we prepare 20 blacklist entries. We therefore add + 20 recipients compared to first test in order to have comparable results. """ + super(TestMassMailBlPerformance, self).setUp() + values = [{ + 'name': 'Recipient %s' % x, + 'email_from': 'Recipient ' % x, + } for x in range(0, 62)] + self.mm_recs = self.env['mass.mail.test.bl'].create(values) + + for x in range(1, 13): + self.env['mail.blacklist'].create({ + 'email': 'rec.%s@example.com' % (x * 5) + }) + + @users('__system__', 'marketing') + @warmup + @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink') + def test_send_mailing_w_bl(self): + mailing = self.env['mail.mass_mailing'].create({ + 'name': 'Test', + 'body_html': '

Hello quuxUnsubscribe

', + 'reply_to_mode': 'email', + 'mailing_model_id': self.ref('test_mass_mailing.model_mass_mail_test_bl'), + 'mailing_domain': [('id', 'in', self.mm_recs.ids)], + }) + + with self.assertQueryCount(__system__=2757, marketing=3509): + mailing.send_mail() + + self.assertEqual(mailing.sent, 50) + self.assertEqual(mailing.delivered, 50)