[FIX][IMP] test_mail: be sure performance test include mail gateway

Purpose of query counter tests is to try to match real life use cases. In
mail those generally involve a correctly configured mail gateway. This is
why we set those parameters in performance tests, leading to a small increase
in some counters.

Task-2661036 (Performance tests data cleanup)
Prepares Task-36879 (MultiCompany Aliases)

Part-of: odoo/odoo#77845
This commit is contained in:
Thibault Delavallée
2021-10-05 16:53:46 +00:00
parent f3a24527d2
commit 201d6bf771
3 changed files with 48 additions and 26 deletions
+29 -19
View File
@@ -48,6 +48,17 @@ class BaseMailPerformance(TransactionCaseWithUserDemo):
# patch registry to simulate a ready environment
self.patch(self.env.registry, 'ready', True)
def _init_mail_gateway(self):
# setup mail gateway
self.alias_domain = 'example.com'
self.alias_catchall = 'catchall.test'
self.alias_bounce = 'bounce.test'
self.default_from = 'notifications'
self.env['ir.config_parameter'].set_param('mail.bounce.alias', self.alias_bounce)
self.env['ir.config_parameter'].set_param('mail.catchall.domain', self.alias_domain)
self.env['ir.config_parameter'].set_param('mail.catchall.alias', self.alias_catchall)
self.env['ir.config_parameter'].set_param('mail.default.from', self.default_from)
@tagged('mail_performance')
class TestBaseMailPerformance(BaseMailPerformance):
@@ -95,6 +106,8 @@ class TestBaseMailPerformance(BaseMailPerformance):
}
])
self._init_mail_gateway()
@users('__system__', 'demo')
@warmup
def test_read_mail(self):
@@ -164,13 +177,13 @@ class TestBaseMailPerformance(BaseMailPerformance):
@warmup
def test_create_mail_with_tracking(self):
""" Create records inheriting from 'mail.thread' (with field tracking). """
with self.assertQueryCount(__system__=7, demo=7):
with self.assertQueryCount(__system__=8, demo=8):
self.env['mail.performance.thread'].create({'name': 'X'})
@users('__system__', 'employee')
@warmup
def test_create_mail_simple(self):
with self.assertQueryCount(__system__=6, employee=6):
with self.assertQueryCount(__system__=7, employee=7):
self.env['mail.test.simple'].create({'name': 'Test'})
@users('__system__', 'employee')
@@ -197,6 +210,8 @@ class TestMailAPIPerformance(BaseMailPerformance):
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
})
self._init_mail_gateway()
# automatically follow activities, for backward compatibility concerning query count
self.env.ref('mail.mt_activities').write({'default': True})
@@ -222,7 +237,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
def test_adv_activity(self):
model = self.env['mail.test.activity']
with self.assertQueryCount(__system__=6, employee=6):
with self.assertQueryCount(__system__=7, employee=7):
model.create({'name': 'Test'})
@users('__system__', 'employee')
@@ -244,7 +259,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
#voip module read activity_type during create leading to one less query in enterprise on action_feedback
category = activity.activity_type_id.category
with self.assertQueryCount(__system__=16, employee=18):
with self.assertQueryCount(__system__=17, employee=19):
activity.action_feedback(feedback='Zizisse Done !')
@users('__system__', 'employee')
@@ -261,7 +276,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
record.write({'name': 'Dupe write'})
with self.assertQueryCount(__system__=17, employee=20):
with self.assertQueryCount(__system__=18, employee=21):
record.action_close('Dupe feedback')
self.assertEqual(record.activity_ids, self.env['mail.activity'])
@@ -364,7 +379,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
def test_message_log_with_post(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(__system__=3, employee=6):
with self.assertQueryCount(__system__=4, employee=7):
record.message_post(
body='<p>Test message_post as log</p>',
subtype_xmlid='mail.mt_note',
@@ -375,7 +390,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
def test_message_post_no_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(__system__=3, employee=6):
with self.assertQueryCount(__system__=4, employee=7):
record.message_post(
body='<p>Test Post Performances basic</p>',
partner_ids=[],
@@ -400,7 +415,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
def test_message_post_one_inbox_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(__system__=11, employee=15):
with self.assertQueryCount(__system__=12, employee=16):
record.message_post(
body='<p>Test Post Performances with an inbox ping</p>',
partner_ids=self.user_test.partner_id.ids,
@@ -466,16 +481,6 @@ class TestMailComplexPerformance(BaseMailPerformance):
'groups_id': [(6, 0, [self.env.ref('base.group_portal').id])],
})
# setup mail gateway
self.env['ir.config_parameter'].sudo().set_param('mail.catchall.domain', 'example.com')
self.env['ir.config_parameter'].sudo().set_param('mail.catchall.alias', 'test-catchall')
self.env['ir.config_parameter'].sudo().set_param('mail.bounce.alias', 'test-bounce')
# prepare recipients to test for more realistic workload
self.customer = self.env['res.partner'].with_context(self._quick_create_ctx).create({
'name': 'Test Customer',
'email': 'test@example.com'
})
self.container = self.env['mail.test.container'].with_context(mail_create_nosubscribe=True).create({
'name': 'Test Container',
'customer_id': self.customer.id,
@@ -489,6 +494,9 @@ class TestMailComplexPerformance(BaseMailPerformance):
self.env.ref('mail.mt_comment').id,
self.env.ref('test_mail.st_mail_test_container_child_full').id]
)
self._init_mail_gateway()
# `test_complex_mail_mail_send`
self.container.flush()
@@ -944,6 +952,8 @@ class TestMailHeavyPerformancePost(BaseMailPerformance):
'res_id': 0,
} for i in range(3)]
self._init_mail_gateway()
@mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('employee')
@warmup
@@ -958,7 +968,7 @@ class TestMailHeavyPerformancePost(BaseMailPerformance):
]
self.attachements = self.env['ir.attachment'].with_user(self.env.user).create(self.vals)
attachement_ids = self.attachements.ids
with self.assertQueryCount(employee=68):
with self.assertQueryCount(employee=70):
self.cr.sql_log = self.warm and self.cr.sql_log_count
record.with_context({}).message_post(
body='<p>Test body <img src="cid:cid1"> <img src="cid:cid2"></p>',
@@ -29,13 +29,15 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
} for x in range(0, 10)
])
self._init_mail_gateway()
@mute_logger('odoo.addons.sms.models.sms_sms')
@users('employee')
@warmup
def test_message_sms_record_1_partner(self):
record = self.test_record.with_user(self.env.user)
pids = self.customer.ids
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=24): # test_mail_enterprise: 19
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=26): # test_mail_enterprise: 26
messages = record._message_sms(
body='Performance Test',
partner_ids=pids,
@@ -50,7 +52,7 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
def test_message_sms_record_10_partners(self):
record = self.test_record.with_user(self.env.user)
pids = self.partners.ids
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=42):
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=44):
messages = record._message_sms(
body='Performance Test',
partner_ids=pids,
@@ -64,7 +66,7 @@ class TestSMSPerformance(BaseMailPerformance, sms_common.SMSCase):
@warmup
def test_message_sms_record_default(self):
record = self.test_record.with_user(self.env.user)
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=27):
with self.mockSMSGateway(sms_allow_unlink=True), self.assertQueryCount(employee=28):
messages = record._message_sms(
body='Performance Test',
)
@@ -22,6 +22,16 @@ class TestMassMailPerformanceBase(TransactionCase):
groups='base.group_user,mass_mailing.group_mass_mailing_user',
name='Martial Marketing', signature='--\nMartial')
# setup mail gateway
self.alias_domain = 'example.com'
self.alias_catchall = 'catchall.test'
self.alias_bounce = 'bounce.test'
self.default_from = 'notifications'
self.env['ir.config_parameter'].set_param('mail.bounce.alias', self.alias_bounce)
self.env['ir.config_parameter'].set_param('mail.catchall.domain', self.alias_domain)
self.env['ir.config_parameter'].set_param('mail.catchall.alias', self.alias_catchall)
self.env['ir.config_parameter'].set_param('mail.default.from', self.default_from)
# patch registry to simulate a ready environment
self.patch(self.env.registry, 'ready', True)
@@ -50,8 +60,8 @@ class TestMassMailPerformance(TestMassMailPerformanceBase):
'mailing_domain': [('id', 'in', self.mm_recs.ids)],
})
# runbot needs +101 compared to local (1567)
with self.assertQueryCount(__system__=1668, marketing=1668):
# runbot needs +101 compared to local (1568)
with self.assertQueryCount(__system__=1669, marketing=1669):
mailing.action_send_mail()
self.assertEqual(mailing.sent, 50)
@@ -90,8 +100,8 @@ class TestMassMailBlPerformance(TestMassMailPerformanceBase):
'mailing_domain': [('id', 'in', self.mm_recs.ids)],
})
# runbot needs +125 compared to local (1833)
with self.assertQueryCount(__system__=1958, marketing=1958):
# runbot needs +125 compared to local (1834)
with self.assertQueryCount(__system__=1959, marketing=1959):
mailing.action_send_mail()
self.assertEqual(mailing.sent, 50)