From 8e85f4e0bd0b1fbbf401686b85d7282f8991454d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 15 Nov 2012 10:15:01 +0100 Subject: [PATCH] [IMP] timeout discipline * Global timeout significantly increased to correctly handle e.g. db creation and teardown * Per-test timeout brought back down to 2s bzr revid: xmo@openerp.com-20121115091501-ys8opo0ccr3dq29h --- addons/web/controllers/testing.py | 2 +- addons/web/doc/testing.rst | 8 +++++--- addons/web/static/src/js/testing.js | 21 ++++++++++++++++++++- addons/web/tests/test_js.py | 2 +- addons/web_tests_demo/static/test/demo.js | 9 +++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/addons/web/controllers/testing.py b/addons/web/controllers/testing.py index 95121f5b192..3c7c4899b6c 100644 --- a/addons/web/controllers/testing.py +++ b/addons/web/controllers/testing.py @@ -54,7 +54,7 @@ TESTING = Template(u""" var oe_db_info = ${db_info}; // List of modules, each module is preceded by its dependencies var oe_all_dependencies = ${dependencies}; - QUnit.config.testTimeout = 10000; + QUnit.config.testTimeout = 5 * 60 * 1000; diff --git a/addons/web/doc/testing.rst b/addons/web/doc/testing.rst index 302ebda9485..84ce8bceb22 100644 --- a/addons/web/doc/testing.rst +++ b/addons/web/doc/testing.rst @@ -297,9 +297,11 @@ test architecture was not warned about asynchronous operations. .. note:: - Asynchronous test cases also have a 10 seconds timeout: if the - test does not finish within 10 seconds, it will be considered - failed. This pretty much always means the test will not resolve. + Asynchronous test cases also have a 2 seconds timeout: if the test + does not finish within 2 seconds, it will be considered + failed. This pretty much always means the test will not + resolve. This timeout *only* applies to the test itself, not to + the setup and teardown processes. .. note:: diff --git a/addons/web/static/src/js/testing.js b/addons/web/static/src/js/testing.js index e124897f063..7686499b939 100644 --- a/addons/web/static/src/js/testing.js +++ b/addons/web/static/src/js/testing.js @@ -286,6 +286,7 @@ openerp.testing = {}; // Always execute tests asynchronously stop(); + var timeout; var teardown = function () { return opts.teardown(instance, $fixture, mock) }; @@ -302,8 +303,25 @@ openerp.testing = {}; + "number of assertions they expect"); } } - return $.when(result).pipe(teardown, teardown); + var d = $.Deferred(); + $.when(result).then(function () { + d.resolve.apply(d, arguments) + }, function () { + d.reject.apply(d, arguments); + }); + if (async || (result && result.then)) { + // async test can be either implicit async (rpc) or + // promise-returning + timeout = setTimeout(function () { + QUnit.config.semaphore = 1; + d.reject({message: "Test timed out"}); + }, 2000); + } + return d.pipe(teardown, teardown); }).always(function () { + if (timeout) { + clearTimeout(timeout); + } start(); }).fail(function (error) { if (options.fail_on_rejection === false) { @@ -320,6 +338,7 @@ openerp.testing = {}; } } + ok(false, "failed!") ok(false, message); }); }); diff --git a/addons/web/tests/test_js.py b/addons/web/tests/test_js.py index d52e2f43806..a126ce4b2f3 100644 --- a/addons/web/tests/test_js.py +++ b/addons/web/tests/test_js.py @@ -14,7 +14,7 @@ class WebSuite(QUnitSuite): password=tools.config['admin_passwd'] or 'admin'), '' ]) - super(WebSuite, self).__init__(url, 20000) + super(WebSuite, self).__init__(url, 50000) def run(self, result): if sql_db._Pool is not None: sql_db._Pool.close_all(sql_db.dsn(tools.config['db_name'])) diff --git a/addons/web_tests_demo/static/test/demo.js b/addons/web_tests_demo/static/test/demo.js index 62cecf6f088..6b80c039107 100644 --- a/addons/web_tests_demo/static/test/demo.js +++ b/addons/web_tests_demo/static/test/demo.js @@ -85,6 +85,15 @@ openerp.testing.section('basic section', function (test) { }); }); + test('timeouting', {asserts: 1}, function () { + var d = $.Deferred(); + setTimeout(function () { + ok(true, "yeah"); + d.resolve('ok') + }, 10000); + return d.promise(); + }); + test('actual RPC', {rpc: 'rpc', asserts: 4}, function (instance) { var Model = new instance.web.Model('web_tests_demo.model'); return Model.call('create', [{name: "Bob"}])