Added tests about timeouts and implemented it in jsonprpc2

bzr revid: nicolas.vanhoren@openerp.com-20131011133054-0dx3wxqcqbdocnlf
This commit is contained in:
niv-openerp
2013-10-11 15:30:54 +02:00
parent e059b1c5c0
commit 083d3fc91e
2 changed files with 55 additions and 1 deletions
+19 -1
View File
@@ -817,7 +817,7 @@ var genericJsonRpc = function(fct_name, params, fct) {
return result.result;
}
}, function() {
console.error("JsonRPC communication error", _.toArray(arguments));
//console.error("JsonRPC communication error", _.toArray(arguments));
var def = $.Deferred();
return def.reject.apply(def, ["communication"].concat(_.toArray(arguments)));
});
@@ -899,11 +899,29 @@ openerp.jsonpRpc = function(url, fct_name, params, settings) {
});
// append the iframe to the DOM (will trigger the first load)
$form.after($iframe);
if (settings.timeout) {
realSetTimeout(function() {
deferred.reject({});
}, settings.timeout);
}
return deferred;
}
});
};
var realSetTimeout = function(fct, millis) {
var finished = new Date().getTime() + millis;
var wait = function() {
var current = new Date().getTime();
if (current < finished) {
setTimeout(wait, finished - current);
} else {
fct();
}
};
setTimeout(wait, millis);
};
openerp.Session = openerp.Class.extend(openerp.PropertiesMixin, {
triggers: {
'request': 'Request sent',
+36
View File
@@ -111,6 +111,42 @@ function (test) {
notEqual(result, origin_tmp, "Values in the different sessions should be different");
});
});*/
test('timeout-jsonrpc', {asserts: 1}, function () {
var session = new openerp.Session();
return session.rpc("/gen_session_id", {}, {timeout: 1}).then(function() {
ok(false, "the request incorrectly succeeded");
return $.when();
}, function(a, e) {
e.preventDefault();
ok(true, "the request correctly failed");
return $.when();
});
});
test('timeout-jsonprpc', {asserts: 1}, function () {
var session = new openerp.Session();
session.origin_server = false;
return session.rpc("/gen_session_id", {}, {timeout: 1}).then(function() {
ok(false, "the request incorrectly succeeded");
return $.when();
}, function(a, e) {
e.preventDefault();
ok(true, "the request correctly failed");
return $.when();
});
});
// desactivated because the phantomjs runner crash
test('timeout-jsonprpc2', {asserts: 1}, function () {
var session = new openerp.Session();
session.origin_server = false;
return session.rpc("/gen_session_id", {}, {force2step: true, timeout: 1}).then(function() {
ok(false, "the request incorrectly succeeded");
return $.when();
}, function(a, e) {
e.preventDefault();
ok(true, "the request correctly failed");
return $.when();
});
});
});
var login = "admin";