[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>
This commit is contained in:
Vincent Schippefilt
2019-12-12 13:22:20 +00:00
parent 89f213001f
commit 6cbfdbce2d
3 changed files with 17 additions and 19 deletions
@@ -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.
+14 -16
View File
@@ -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)");
});
await concurrency.delay(1);
assert.verifySteps(['function_called 2'],
"should have called the function twice (2nd time from reset)");
});
});
@@ -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);
});
});