Skip to content
Snippets Groups Projects
Commit b971d9c4 authored by Thibault Delavallée's avatar Thibault Delavallée
Browse files

[IMP] test_mail: add performance tests to cover more separate features

This commit is a manual forward-port of saas-11.2's 42659dc7 .

In test_mail there are performance tests involving several followers and give
counters for some heavy real-life-like use cases. Purpose of this commit is to
have more basic performance tests for main mail features, like simple post,
simple subscription of one follower. It allows to have an idea of the basic
cost of various features.

Adding use cases for message_post includes
 * posting without followers (aka, no notification)
 * posting with a ping (by email or by inbox)
 * logging a note with optimized method _message_log or with message_post

Adding use cases for activities includes setting an activity as done. This
action posts a message and is therefore interesting to evaluate.

Adding use cases for subscription includes
 * adding and re-adding one follower, with default or specified subtypes
 * updating responsible field triggering a simple tracking and an assignation
   email or notification (not completely supported in saas 11.2 meaning this
   counter will increase when forward-ported)
 * note that some subscription tests have already been added at a01933c9

Finally some heavier tests are added for assignation and tracking based
on QWeb view.

This commit is related to task ID 1824965 . This one is an ongoing task
and several commits may be linked to that task.
parent 19849785
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="st_mail_test_simple_external" model="mail.message.subtype">
<field name="name">External subtype</field>
<field name="description">External subtype</field>
<field name="res_model">mail.test.simple</field>
<field name="default" eval="False"/>
<field name="internal" eval="False"/>
</record>
<record id="st_mail_test_full_umbrella_upd" model="mail.message.subtype">
<field name="name">Umbrella Changed Subtype</field>
<field name="description">Umbrella Changed</field>
......
......@@ -131,6 +131,17 @@ class TestAdvMailPerformance(TransactionCase):
'notification_type': 'inbox',
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
})
self.customer = self.env['res.partner'].with_context(self._quick_create_ctx).create({
'name': 'Test Customer',
'email': 'test@example.com',
})
self.user_test = self.env['res.users'].with_context(self._quick_create_ctx).create({
'name': 'Paulette Testouille',
'login': 'paul',
'email': 'p.p@example.com',
'notification_type': 'inbox',
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])],
})
@users('admin', 'emp')
@warmup
......@@ -145,17 +156,125 @@ class TestAdvMailPerformance(TransactionCase):
@mute_logger('odoo.models.unlink')
def test_adv_activity_full(self):
record = self.env['mail.test.activity'].create({'name': 'Test'})
model = self.env['mail.activity'].with_context({
MailActivity = self.env['mail.activity'].with_context({
'default_res_model': 'mail.test.activity',
})
with self.assertQueryCount(admin=26, emp=32): # test_mail only: 26 - 32
model.create({
activity = MailActivity.create({
'summary': 'Test Activity',
'res_id': record.id,
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
})
with self.assertQueryCount(admin=84, emp=116): # com runbot 84 - 116 // test_mail only: 68 - 96
activity.action_feedback(feedback='Zizisse Done !')
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_message_assignation_email(self):
self.user_test.write({'notification_type': 'email'})
record = self.env['mail.test.track'].create({'name': 'Test'})
with self.assertQueryCount(admin=80, emp=109): # test_mail only: 69 - 96
record.write({
'user_id': self.user_test.id,
})
@users('admin', 'emp')
@warmup
def test_message_assignation_inbox(self):
record = self.env['mail.test.track'].create({'name': 'Test'})
with self.assertQueryCount(admin=22, emp=28): # test_mail only: 20 - 26
record.write({
'user_id': self.user_test.id,
})
@users('admin', 'emp')
@warmup
def test_message_log(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=5, emp=5): # test_mail only: 3 - 3
record._message_log(
body='<p>Test _message_log</p>',
message_type='comment')
@users('admin', 'emp')
@warmup
def test_message_log_with_post(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=31, emp=43): # test_mail only: 29 - 40
record.message_post(
body='<p>Test message_post as log</p>',
subtype='mail.mt_note',
message_type='comment')
@users('admin', 'emp')
@warmup
def test_message_post_no_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=31, emp=43): # test_mail only: 29 - 40
record.message_post(
body='<p>Test Post Performances basic</p>',
partner_ids=[],
message_type='comment',
subtype='mail.mt_comment')
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_message_post_one_email_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=85, emp=115): # com runbot 83 - 112 // test_mail only: 81 - 110
record.message_post(
body='<p>Test Post Performances with an email ping</p>',
partner_ids=self.customer.ids,
message_type='comment',
subtype='mail.mt_comment')
@users('admin', 'emp')
@warmup
def test_message_post_one_inbox_notification(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=44, emp=58): # com runbot 42 - 55 // test_mail only: 42 - 55
record.message_post(
body='<p>Test Post Performances with an inbox ping</p>',
partner_ids=self.user_test.partner_id.ids,
message_type='comment',
subtype='mail.mt_comment')
@mute_logger('odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_message_subscribe_default(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
with self.assertQueryCount(admin=7, emp=8): # test_mail only: 7 - 8
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
with self.assertQueryCount(admin=19, emp=19): # test_mail only: 19 - 19
record.message_subscribe(partner_ids=self.user_test.partner_id.ids)
@mute_logger('odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_message_subscribe_subtypes(self):
record = self.env['mail.test.simple'].create({'name': 'Test'})
subtype_ids = (self.env.ref('test_mail.st_mail_test_simple_external') | self.env.ref('mail.mt_comment')).ids
with self.assertQueryCount(admin=7, emp=8): # test_mail only: 7 - 8
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
with self.assertQueryCount(admin=19, emp=19): # test_mail only: 18 - 18
record.message_subscribe(partner_ids=self.user_test.partner_id.ids, subtype_ids=subtype_ids)
class TestHeavyMailPerformance(TransactionCase):
......@@ -326,9 +445,35 @@ class TestHeavyMailPerformance(TransactionCase):
@mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_complex_create_tracking_subscription(self):
""" Create record using most features: auto subscription, tracking
and templates. """
def test_complex_tracking_assignation(self):
""" Assignation performance test on already-created record """
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': self.umbrella.id,
'customer_id': self.customer.id,
'user_id': self.env.uid,
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id)
with self.assertQueryCount(admin=87, emp=117): # test_mail only: 76 - 104
rec.write({'user_id': self.user_portal.id})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
# write tracking message
self.assertEqual(rec.message_ids[0].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[0].needaction_partner_ids, self.env['res.partner'])
# create tracking message
self.assertEqual(rec.message_ids[1].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd'))
self.assertEqual(rec.message_ids[1].needaction_partner_ids, self.partners)
# creation message
self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.env['res.partner'])
@mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_complex_tracking_subscription_create(self):
""" Creation performance test involving auto subscription, assignation, tracking with subtype and template send. """
umbrella_id = self.umbrella.id
customer_id = self.customer.id
user_id = self.user_portal.id
......@@ -342,7 +487,7 @@ class TestHeavyMailPerformance(TransactionCase):
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
# tracking message
# create tracking message
self.assertEqual(rec.message_ids[0].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd'))
self.assertEqual(rec.message_ids[0].needaction_partner_ids, self.partners | self.user_portal.partner_id)
# creation message
......@@ -352,12 +497,40 @@ class TestHeavyMailPerformance(TransactionCase):
@mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_complex_write_tracking_subscription(self):
""" Create record using most features: auto subscription, tracking
and templates. """
def test_complex_tracking_subscription_subtype(self):
""" Write performance test involving auto subscription, tracking with subtype """
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': False,
'customer_id': False,
'user_id': self.user_portal.id,
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
with self.assertQueryCount(admin=236, emp=275): # test_mail only: 230 - 268
rec.write({
'name': 'Test2',
'umbrella_id': self.umbrella.id,
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
# write tracking message
self.assertEqual(rec.message_ids[0].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd'))
self.assertEqual(rec.message_ids[0].needaction_partner_ids, self.partners | self.user_portal.partner_id)
# create tracking message
self.assertEqual(rec.message_ids[1].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[1].needaction_partner_ids, self.env['res.partner'])
# creation message
self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.env['res.partner'])
@mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_complex_tracking_subscription_write(self):
""" Write performance test involving auto subscription, tracking with subtype and template send """
umbrella_id = self.umbrella.id
customer_id = self.customer.id
user_id = self.user_portal.id
umbrella2 = self.env['mail.test'].with_context(mail_create_nosubscribe=True).create({
'name': 'Test Umbrella 2',
'customer_id': False,
......@@ -368,7 +541,7 @@ class TestHeavyMailPerformance(TransactionCase):
'name': 'Test',
'umbrella_id': umbrella2.id,
'customer_id': False,
'user_id': user_id,
'user_id': self.user_portal.id,
})
self.assertEqual(rec.message_partner_ids, self.user_portal.partner_id | self.env.user.partner_id)
......@@ -389,3 +562,39 @@ class TestHeavyMailPerformance(TransactionCase):
# creation message
self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.env['res.partner'])
@mute_logger('odoo.tests', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
@users('admin', 'emp')
@warmup
def test_complex_tracking_template(self):
""" Write performance test involving assignation, tracking with template """
customer_id = self.customer.id
rec = self.env['mail.test.full'].create({
'name': 'Test',
'umbrella_id': self.umbrella.id,
'customer_id': False,
'user_id': self.user_portal.id,
'mail_template': self.env.ref('test_mail.mail_test_full_tracking_tpl').id,
})
self.assertEqual(rec.message_partner_ids, self.partners | self.env.user.partner_id | self.user_portal.partner_id)
with self.assertQueryCount(admin=72, emp=101): # test_mail only: 64 - 91
rec.write({
'name': 'Test2',
'customer_id': customer_id,
'user_id': self.env.uid,
})
# write template message (sent to customer, mass mailing kept for history)
self.assertEqual(rec.message_ids[0].subtype_id, self.env['mail.message.subtype'])
self.assertEqual(rec.message_ids[0].subject, 'Test Template')
# write tracking message
self.assertEqual(rec.message_ids[1].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[1].needaction_partner_ids, self.env['res.partner'])
# create tracking message
self.assertEqual(rec.message_ids[2].subtype_id, self.env.ref('test_mail.st_mail_test_full_umbrella_upd'))
self.assertEqual(rec.message_ids[2].needaction_partner_ids, self.partners | self.user_portal.partner_id)
# creation message
self.assertEqual(rec.message_ids[3].subtype_id, self.env.ref('mail.mt_note'))
self.assertEqual(rec.message_ids[3].needaction_partner_ids, self.env['res.partner'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment