From f7e0da7b71fae4c0c9936335100cd15a598c4fae Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Fri, 9 Sep 2022 09:15:26 +0000 Subject: [PATCH] [IMP] mail: improve after event error stack trace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit the error raised/logged when rejecting the afterEvent promise was imcomplete. This is due to the fact we're creating the error inside the promise itself. In order to get a better stack trace, the error is now declared outside of the promise. Moreover, both `afterNextRender` and `afterEvent` functions were using `console.error` before rejecting the promise. This is also a problem since runbot will show the error printed by `console.error` instead of the one of the test failure. In order to solve this issue, those two `console.error` have been replaced by `console.warn`. closes odoo/odoo#99899 Signed-off-by: Sébastien Theys (seb) --- addons/mail/static/tests/helpers/test_utils.js | 15 ++++++++------- addons/web/static/tests/owl2_compatibility_app.js | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index 48c7f643e33..dd833dc333f 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -69,14 +69,12 @@ function getAfterEvent({ messagingBus }) { * @returns {Promise} */ return async function afterEvent({ eventName, func, message, predicate, timeoutDelay = 5000 }) { + const error = new Error(message || `Timeout: the event ${eventName} was not triggered.`); // Set up the timeout to reject if the event is not triggered. let timeoutNoEvent; const timeoutProm = new Promise((resolve, reject) => { timeoutNoEvent = setTimeout(() => { - let error = message - ? new Error(message) - : new Error(`Timeout: the event ${eventName} was not triggered.`); - console.error(error); + console.warn(error); reject(error); }, timeoutDelay); }); @@ -92,9 +90,12 @@ function getAfterEvent({ messagingBus }) { // promise has been registered to not miss any potential event. const funcRes = func(); // Make them race (first to resolve/reject wins). - await Promise.race([eventProm, timeoutProm]); - clearTimeout(timeoutNoEvent); - messagingBus.removeEventListener(eventName, eventHandler); + await Promise.race([eventProm, timeoutProm]).finally(() => { + // Execute clean up regardless of whether the promise is + // rejected or not. + clearTimeout(timeoutNoEvent); + messagingBus.removeEventListener(eventName, eventHandler); + }); // If the event is triggered before the end of the async function, // ensure the function finishes its job before returning. return await funcRes; diff --git a/addons/web/static/tests/owl2_compatibility_app.js b/addons/web/static/tests/owl2_compatibility_app.js index 8621a11b7cf..6a3431995bb 100644 --- a/addons/web/static/tests/owl2_compatibility_app.js +++ b/addons/web/static/tests/owl2_compatibility_app.js @@ -54,7 +54,7 @@ if (runningSchedulers.length) { error = stopError; } - console.error( + console.warn( error, runningSchedulers.map((s) => [...s.tasks].map((f) => [f, f.node.status])), runningSchedulers