summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2019-12-12 09:44:51 +0000
committerVincent Schippefilt <vsc@odoo.com>2019-12-12 13:22:20 +0000
commit6cbfdbce2d0f1b567b6a6d6f637fe2a476980acc (patch)
treec98462b68793dbe51fef8225a513e0ea40db9539
parent89f213001fc016a46c8236891e8028d26ff27bb4 (diff)
[FIX] mail: Timer(s) tests nondeterministic behavior
Timer test relies on setTimeout(..., 0) for its execution and its verification. However it seems that in the browser there is *not always* a guarantee that 2 setTimeout(...,0) will execute in a specific order. Delaying the verification by 1 ms : setTimeout(..., 1) should force the order of execution. closes odoo/odoo#41732 Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
-rw-r--r--addons/mail/static/src/js/models/utils/timer.js2
-rw-r--r--addons/mail/static/tests/models/timer_tests.js30
-rw-r--r--addons/mail/static/tests/models/timers_tests.js4
3 files changed, 17 insertions, 19 deletions
diff --git a/addons/mail/static/src/js/models/utils/timer.js b/addons/mail/static/src/js/models/utils/timer.js
index a3236fd1a16..9aaae471d2d 100644
--- a/addons/mail/static/src/js/models/utils/timer.js
+++ b/addons/mail/static/src/js/models/utils/timer.js
@@ -13,7 +13,7 @@ var Timer = Class.extend({
* initialization (@see start method).
*
* @param {Object} params
- * @param {integer} params.duration duration of timer before timeout in
+ * @param {number} params.duration duration of timer before timeout in
* milli-seconds.
* @param {function} params.onTimeout function that is called when the
* timer times out.
diff --git a/addons/mail/static/tests/models/timer_tests.js b/addons/mail/static/tests/models/timer_tests.js
index 9a66e80ad22..1a4e7c2726f 100644
--- a/addons/mail/static/tests/models/timer_tests.js
+++ b/addons/mail/static/tests/models/timer_tests.js
@@ -3,6 +3,7 @@ odoo.define('mail.model.TimerTests', function (require) {
var testUtils = require("web.test_utils");
var Timer = require('mail.model.Timer');
+var concurrency = require('web.concurrency');
QUnit.module('mail', {}, function () {
QUnit.module('model', {}, function () {
@@ -20,9 +21,8 @@ QUnit.test('start()', async function (assert) {
assert.verifySteps([], "should not have called the function");
t.start();
- await prom.then(function () {
- assert.ok(true, "should have called the function");
- });
+ await prom;
+ assert.ok(true, "should have called the function");
});
QUnit.test('clear()', function (assert) {
@@ -44,15 +44,17 @@ QUnit.test('clear()', function (assert) {
setTimeout(function () {
assert.verifySteps([], "should not have called the function");
done();
- }, 0);
+ }, 1);
});
QUnit.test('reset()', async function (assert) {
assert.expect(4);
- var prom = testUtils.makeTestPromise();
+ var i = 0;
+
var func = function () {
- assert.step('function_called');
+ ++i;
+ assert.step('function_called ' + i);
};
var t = new Timer({
duration: 0,
@@ -62,18 +64,14 @@ QUnit.test('reset()', async function (assert) {
t.start();
// Called after 1st timer timeout
- await testUtils.nextTick();
- assert.verifySteps(['function_called'], "should have called the function once");
+ await concurrency.delay(1);
+ assert.verifySteps(['function_called 1'], "should have called the function once");
t.reset();
- // Called after 2nd timer timeout
- setTimeout(function () {
- prom.resolve();
- }, 0);
- await prom.then(function () {
- assert.verifySteps(['function_called'],
- "should have called the function twice (2nd time from reset)");
- });
+ // Called after 2nd timer timeout
+ await concurrency.delay(1);
+ assert.verifySteps(['function_called 2'],
+ "should have called the function twice (2nd time from reset)");
});
});
diff --git a/addons/mail/static/tests/models/timers_tests.js b/addons/mail/static/tests/models/timers_tests.js
index eeaf2e2a8f6..ccc15c4b69d 100644
--- a/addons/mail/static/tests/models/timers_tests.js
+++ b/addons/mail/static/tests/models/timers_tests.js
@@ -60,7 +60,7 @@ QUnit.test('register timers once per ID', function (assert) {
setTimeout(function () {
assert.verifySteps(['function_called'], "should have called the function once");
done();
- }, 0);
+ }, 1);
});
QUnit.test('unregister timers', function (assert) {
@@ -82,7 +82,7 @@ QUnit.test('unregister timers', function (assert) {
setTimeout(function () {
assert.verifySteps([], "should not have called the function");
done();
- }, 0);
+ }, 1);
});
});