From 0c8b5c5da82c01413f6f548d081c5522d21de0df Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 5 Oct 2021 09:59:19 +0000 Subject: [PATCH] [FIX] web: attempt to fix non deterministic issue in tests This commit *could* prevent a test from failing randomly. The important part in the diff is the switch from $.Deferred to native Promise. JQuery Deferred behave differently upon resolution (it is sync if the deferred is resolved directly, whereas it is not the case for native Promise). I couldn't find any other reason to explain why the test was sometimes failing. There is no reason to use Deferred anyway. The issue didn't occur after this commit in more than 600 builds. [1] https://runbot.odoo.com/web#id=2297&action=573&model=runbot.build.error&view_type=form&cids=1&menu_id=405 X-original-commit: ed0761dce44bd37cdd9d40ddd6e021517f466f97 Part-of: odoo/odoo#78698 --- addons/web/static/tests/legacy/views/form_tests.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/addons/web/static/tests/legacy/views/form_tests.js b/addons/web/static/tests/legacy/views/form_tests.js index b3706eba4d9..e67eee6bff5 100644 --- a/addons/web/static/tests/legacy/views/form_tests.js +++ b/addons/web/static/tests/legacy/views/form_tests.js @@ -1895,9 +1895,9 @@ QUnit.module('Views', { willStart: function () { assert.step('load '+rpcCount); if (rpcCount === 2) { - return $.Deferred(); + return new Promise(() => {}); } - return $.Deferred().resolve(); + return Promise.resolve(); }, })); @@ -1924,7 +1924,7 @@ QUnit.module('Views', { }); assert.verifySteps(['load 1']); - await testUtils.mock.intercept(form, 'execute_action', function (ev) { + testUtils.mock.intercept(form, 'execute_action', function (ev) { ev.data.on_success(); ev.data.on_closed(); }); @@ -1932,11 +1932,6 @@ QUnit.module('Views', { await testUtils.dom.click('.o_form_statusbar button.p', form); assert.verifySteps(['load 2']); - testUtils.mock.intercept(form, 'execute_action', function (ev) { - ev.data.on_success(); - ev.data.on_closed(); - }); - await testUtils.dom.click('.o_form_statusbar button.p', form); assert.verifySteps(['load 3']);