diff options
| author | XavierDo <xdo@odoo.com> | 2019-02-06 12:10:36 +0000 |
|---|---|---|
| committer | XavierDo <xdo@odoo.com> | 2019-02-07 12:53:14 +0000 |
| commit | 5c3aaacd2e5748b3f104f5ee033b442582d44c07 (patch) | |
| tree | f66a0af24d0bb6ce135a85738f087cb6af915d20 /addons/mail/static/src/js/services/mail_status_manager.js | |
| parent | 2d45df1081c568c3b306fae18b9284878756c85b (diff) | |
[IMP] mail: correctly patch mail status manager timers
We want to avoid that a `setTimeout` started in one test has an impact on other
tests. This is especially true with the status update loop. Since mail_service
is used in multiple tests, the safest solution is to patch timeouts everytime
we make a call to getMailServices.
There is no need for an unpatch, the patch become the default behaviour until
the page is refresh at the end of tests.
It is possible to manually add the patch after calling `getMailServices`
```
this.services = mailTestUtils.getMailServices(this);
this.timeoutMock = mailTestUtils.patchMailTimeouts();
```
This can be usefull if we want to get the timeoutMock to simulate time changes.
Task: 1856205
Diffstat (limited to 'addons/mail/static/src/js/services/mail_status_manager.js')
| -rw-r--r-- | addons/mail/static/src/js/services/mail_status_manager.js | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/addons/mail/static/src/js/services/mail_status_manager.js b/addons/mail/static/src/js/services/mail_status_manager.js index 2b75cdc6ee7..5ca151d47bf 100644 --- a/addons/mail/static/src/js/services/mail_status_manager.js +++ b/addons/mail/static/src/js/services/mail_status_manager.js @@ -3,6 +3,7 @@ odoo.define('mail.Manager.Status', function (require) { var core = require('web.core'); var MailManager = require('mail.Manager'); +var mailUtils = require('mail.utils'); var QWeb = core.qweb; /** @@ -33,8 +34,8 @@ MailManager.include({ // Add to list to call it in next bus update or _fetchMissingImStatus this._imStatus[partnerID] = undefined; // fetch after some time if no other getImStatus occurs - this._clearStatusServiceTimeout(this._fetchStatusTimeout); - this._fetchStatusTimeout = this._setStatusServiceTimeout(function () { + mailUtils.clearTimeout(this._fetchStatusTimeout); + this._fetchStatusTimeout = mailUtils.setTimeout(function () { self._fetchMissingImStatus(); }, 500); } @@ -68,15 +69,6 @@ MailManager.include({ //-------------------------------------------------------------------------- /** - * A simple clearTimeout, useful for test - * - * @private - * @param {integer} ids - */ - _clearStatusServiceTimeout: function (id) { - clearTimeout(id); - }, - /** * Fetch the list of im_status for partner with id in ids list and triggers * an update. * @@ -169,17 +161,6 @@ MailManager.include({ }); }, /** - * A simple setTimeout, useful for test - * - * @private - * @param {function} func - * @param {integer} duration - * @return {integer} - */ - _setStatusServiceTimeout: function (func, duration) { - return setTimeout(func, duration); - }, - /** * Once initialised, this loop will update the im_status of registered * users. * @@ -191,7 +172,7 @@ MailManager.include({ if (!_.isNumber(counter)) { counter = 0; } - this._setStatusServiceTimeout(function () { + mailUtils.setTimeout(function () { if (counter >= self._UPDATE_INTERVAL && self._isTabFocused) { self._fetchImStatus({ partnerIDs: self._getImStatusToUpdate() }); counter = 0; |
