Commit 7603944f authored by Tristan Cavelier's avatar Tristan Cavelier

fix test timeout issues

parent 0a307d7f
/*jslint indent: 2, maxlen: 80, nomen: true */ /*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, RSVP, jIO, fake_storage, module, test, stop, start, deepEqual, /*global define, RSVP, jIO, fake_storage, module, test, stop, start, deepEqual,
setTimeout, clearTimeout, XMLHttpRequest, window */ setTimeout, clearTimeout, XMLHttpRequest, window, ok */
(function (dependencies, factory) { (function (dependencies, factory) {
"use strict"; "use strict";
...@@ -163,7 +163,7 @@ ...@@ -163,7 +163,7 @@
}, "Get document, nothing to synchronize."); }, "Get document, nothing to synchronize.");
// check storage state // check storage state
return sleep(500). return sleep(1000).
// possible synchronization in background (should not occur) // possible synchronization in background (should not occur)
then(function () { then(function () {
return all(jio_list.map(function (jio) { return all(jio_list.map(function (jio) {
...@@ -201,11 +201,16 @@ ...@@ -201,11 +201,16 @@
} }
function getDocumentWithSynchronizationTest(answer) { function getDocumentWithSynchronizationTest(answer) {
if (answer && answer.data) {
ok(shared.modified_date_list.map(function (v) {
return (v && v.toJSON()) || undefined;
}).indexOf(answer.data.modified) !== -1, "Should be a known date");
delete answer.data.modified;
}
deepEqual(answer, { deepEqual(answer, {
"data": { "data": {
"_id": "{\"identifier\":[\"b\"]}", "_id": "{\"identifier\":[\"b\"]}",
"identifier": "b", "identifier": "b"
"modified": shared.modified_date_list[0].toJSON()
}, },
"id": "{\"identifier\":[\"b\"]}", "id": "{\"identifier\":[\"b\"]}",
"method": "get", "method": "get",
...@@ -215,7 +220,7 @@ ...@@ -215,7 +220,7 @@
}, "Get document, pending synchronization."); }, "Get document, pending synchronization.");
// check storage state // check storage state
return sleep(500). return sleep(1000).
// synchronizing in background // synchronizing in background
then(function () { then(function () {
return all(jio_list.map(function (jio) { return all(jio_list.map(function (jio) {
...@@ -251,11 +256,16 @@ ...@@ -251,11 +256,16 @@
} }
function getDocumentWith404SynchronizationTest(answer) { function getDocumentWith404SynchronizationTest(answer) {
if (answer && answer.data) {
ok(shared.modified_date_list.map(function (v) {
return (v && v.toJSON()) || undefined;
}).indexOf(answer.data.modified) !== -1, "Should be a known date");
delete answer.data.modified;
}
deepEqual(answer, { deepEqual(answer, {
"data": { "data": {
"_id": "{\"identifier\":[\"c\"]}", "_id": "{\"identifier\":[\"c\"]}",
"identifier": "c", "identifier": "c"
"modified": shared.modified_date_list[1].toJSON()
}, },
"id": "{\"identifier\":[\"c\"]}", "id": "{\"identifier\":[\"c\"]}",
"method": "get", "method": "get",
...@@ -265,7 +275,7 @@ ...@@ -265,7 +275,7 @@
}, "Get document, synchronizing with not found document."); }, "Get document, synchronizing with not found document.");
// check storage state // check storage state
return sleep(500). return sleep(1000).
// synchronizing in background // synchronizing in background
then(function () { then(function () {
return all(jio_list.map(function (jio) { return all(jio_list.map(function (jio) {
...@@ -309,11 +319,16 @@ ...@@ -309,11 +319,16 @@
} }
function getDocumentWithUnavailableStorageTest(answer) { function getDocumentWithUnavailableStorageTest(answer) {
if (answer && answer.data) {
ok(shared.modified_date_list.map(function (v) {
return (v && v.toJSON()) || undefined;
}).indexOf(answer.data.modified) !== -1, "Should be a known date");
delete answer.data.modified;
}
deepEqual(answer, { deepEqual(answer, {
"data": { "data": {
"_id": "{\"identifier\":[\"d\"]}", "_id": "{\"identifier\":[\"d\"]}",
"identifier": "d", "identifier": "d"
"modified": shared.modified_date_list[1].toJSON()
}, },
"id": "{\"identifier\":[\"d\"]}", "id": "{\"identifier\":[\"d\"]}",
"method": "get", "method": "get",
...@@ -324,7 +339,7 @@ ...@@ -324,7 +339,7 @@
unsetFakeStorage(); unsetFakeStorage();
// check storage state // check storage state
return sleep(500). return sleep(1000).
// synchronizing in background // synchronizing in background
then(function () { then(function () {
return all(jio_list.map(function (jio) { return all(jio_list.map(function (jio) {
...@@ -479,6 +494,8 @@ ...@@ -479,6 +494,8 @@
"status": 201, "status": 201,
"statusText": "Created" "statusText": "Created"
}, "Post document"); }, "Post document");
return sleep(100);
} }
function checkStorageContent() { function checkStorageContent() {
...@@ -518,6 +535,8 @@ ...@@ -518,6 +535,8 @@
"status": 204, "status": 204,
"statusText": "No Content" "statusText": "No Content"
}, "Update document"); }, "Update document");
return sleep(100);
} }
function checkStorageContent3() { function checkStorageContent3() {
...@@ -719,6 +738,8 @@ ...@@ -719,6 +738,8 @@
"status": 204, "status": 204,
"statusText": "No Content" "statusText": "No Content"
}, "Remove document"); }, "Remove document");
return sleep(100);
} }
function checkStorageContent() { function checkStorageContent() {
...@@ -1234,12 +1255,12 @@ ...@@ -1234,12 +1255,12 @@
fake_storage.commands[ fake_storage.commands[
"replicate scenario test for repair method - 1/allDocs" "replicate scenario test for repair method - 1/allDocs"
].error({"status": 0}); ].error({"status": 0});
}, 100); }, 250);
setTimeout(function () { setTimeout(function () {
fake_storage.commands[ fake_storage.commands[
"replicate scenario test for repair method - 1/allDocs" "replicate scenario test for repair method - 1/allDocs"
].error({"status": 0}); ].error({"status": 0});
}, 200); }, 500);
return replicate_jio.repair({"_id": "{\"identifier\":[\"d\"]}"}); return replicate_jio.repair({"_id": "{\"identifier\":[\"d\"]}"});
} }
......
...@@ -146,6 +146,11 @@ ...@@ -146,6 +146,11 @@
}); });
stop(); stop();
setTimeout(function () {
ok(!called, "callback " + (called ? "" : "not") + " called");
}, 1999);
jio.post({}).always(function (answer) { jio.post({}).always(function (answer) {
var message = (answer && answer.message) || "Timeout"; var message = (answer && answer.message) || "Timeout";
called = true; called = true;
...@@ -168,10 +173,6 @@ ...@@ -168,10 +173,6 @@
commands['3 No Respons/post'].free(); commands['3 No Respons/post'].free();
}, 100); }, 100);
setTimeout(function () {
ok(!called, "callback " + (called ? "" : "not") + " called");
}, 1999);
i = setTimeout(function () { i = setTimeout(function () {
i = undefined; i = undefined;
start(); start();
...@@ -189,6 +190,11 @@ ...@@ -189,6 +190,11 @@
}); });
stop(); stop();
setTimeout(function () {
ok(!called, "callback " + (called ? "" : "not") + " called");
}, 2999);
jio.post({}, {"timeout": 3000}).always(function (answer) { jio.post({}, {"timeout": 3000}).always(function (answer) {
var message = (answer && answer.message) || "Timeout"; var message = (answer && answer.message) || "Timeout";
called = true; called = true;
...@@ -211,10 +217,6 @@ ...@@ -211,10 +217,6 @@
commands['4 No Respons/post'].free(); commands['4 No Respons/post'].free();
}, 1000); }, 1000);
setTimeout(function () {
ok(!called, "callback " + (called ? "" : "not") + " called");
}, 2999);
i = setTimeout(function () { i = setTimeout(function () {
i = undefined; i = undefined;
start(); start();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment