summaryrefslogtreecommitdiff
path: root/share/www/script
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2010-04-06 19:54:04 +0000
committerJohn Christopher Anderson <jchris@apache.org>2010-04-06 19:54:04 +0000
commitc6b27a3d4fbd4dcbf5716720af5be4e31bf2a8c7 (patch)
tree3aaa47c50596f0e5e62c37406812f8ca3b88e204 /share/www/script
parent8897dbe40941295009d156bf77eb0bf40abc5136 (diff)
use waitForSuccess to timeout changes requests that never succeed
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@931297 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script')
-rw-r--r--share/www/script/couch_tests.js16
-rw-r--r--share/www/script/test/changes.js94
-rw-r--r--share/www/script/test/oauth.js23
3 files changed, 66 insertions, 67 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index 3978d483..943b851b 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -149,6 +149,22 @@ function stringFun(fun) {
return string;
}
+function waitForSuccess(fun, tag) {
+ var start = new Date();
+ while(true) {
+ if (new Date() - start > 5000) {
+ throw("timeout: "+tag);
+ } else {
+ try {
+ fun();
+ break;
+ } catch (e) {}
+ // sync http req allow async req to happen
+ CouchDB.request("GET", "/test_suite_db/?tag="+encodeURIComponent(tag));
+ }
+ }
+}
+
function waitForRestart() {
var waiting = true;
while (waiting) {
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index c36b3060..226204ef 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -76,15 +76,12 @@ couchTests.changes = function(debug) {
var docBar = {_id:"bar", bar:1};
db.save(docBar);
- while(true) {
- var lines = xhr.responseText.split("\n");
- try {
- var change1 = JSON.parse(lines[0]);
- var change2 = JSON.parse(lines[1]);
- break;
- } catch (e) {}
- db.info() // sync http req allow async req to happen
- }
+ var lines, change1, change2;
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ change1 = JSON.parse(lines[0]);
+ change2 = JSON.parse(lines[1]);
+ }, "bar-only");
T(change1.seq == 1)
T(change1.id == "foo")
@@ -97,15 +94,12 @@ couchTests.changes = function(debug) {
var docBaz = {_id:"baz", baz:1};
db.save(docBaz);
- while(true) {
- var lines = xhr.responseText.split("\n");
- try {
- var change3 = JSON.parse(lines[2]);
- break;
- } catch (e) {}
- db.info() // sync http req allow async req to happen
-
- }
+ var change3;
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ change3 = JSON.parse(lines[2]);
+ });
+
T(change3.seq == 3);
T(change3.id == "baz");
T(change3.changes[0].rev == docBaz._rev);
@@ -117,12 +111,13 @@ couchTests.changes = function(debug) {
xhr.open("GET", "/test_suite_db/_changes?feed=continuous&heartbeat=10", true);
xhr.send("");
- str = xhr.responseText;
- while(str.charAt(str.length - 1) != "\n" ||
- str.charAt(str.length - 2) != "\n") {
- db.info() // sync http req allow async req to happen
- str = xhr.responseText;
- }
+ var str;
+ waitForSuccess(function() {
+ str = xhr.responseText;
+ if (str.charAt(str.length - 1) != "\n" || str.charAt(str.length - 2) != "\n") {
+ throw("keep waiting");
+ }
+ }, "heartbeat");
T(str.charAt(str.length - 1) == "\n")
T(str.charAt(str.length - 2) == "\n")
@@ -134,15 +129,12 @@ couchTests.changes = function(debug) {
xhr.open("GET", "/test_suite_db/_changes?feed=longpoll", true);
xhr.send("");
- while(true) {
- try {
- var lines = xhr.responseText.split("\n");
- if(lines[5]=='"last_seq":3}') {
- break;
- }
- } catch (e) {}
- db.info(); // sync http req allow async req to happen
- }
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ if (lines[5] != '"last_seq":3}') {
+ throw("still waiting");
+ }
+ }, "last_seq");
xhr = CouchDB.newXhr();
@@ -161,14 +153,12 @@ couchTests.changes = function(debug) {
return JSON.parse(linetrimmed);
}
- while(true) {
- try {
- var lines = xhr.responseText.split("\n");
- if(lines[3]=='"last_seq":4}')
- break;
- } catch (e) {}
- db.info(); // sync http req allow async req to happen
- }
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ if (lines[3] != '"last_seq":4}') {
+ throw("still waiting");
+ }
+ }, "change_lines");
var change = parse_changes_line(lines[1]);
T(change.seq == 4);
@@ -229,13 +219,9 @@ couchTests.changes = function(debug) {
db.save({"_id":"falsy", "bop" : ""}); // empty string is falsy
db.save({"_id":"bingo","bop" : "bingo"});
- while(true) {
- try {
- var resp = JSON.parse(xhr.responseText);
- break;
- } catch (e) {}
- db.info() // sync http req allow async req to happen
- }
+ waitForSuccess(function() {
+ resp = JSON.parse(xhr.responseText);
+ }, "longpoll-since");
T(resp.last_seq == 9);
T(resp.results && resp.results.length > 0 && resp.results[0]["id"] == "bingo", "filter the correct update");
@@ -246,14 +232,10 @@ couchTests.changes = function(debug) {
xhr.send("");
db.save({"_id":"rusty", "bop" : "plankton"});
- while(true) {
- try {
- var lines = xhr.responseText.split("\n");
- JSON.parse(lines[3])
- break;
- } catch (e) {}
- db.info() // sync http req allow async req to happen
- }
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ JSON.parse(lines[3]);
+ }, "continuous-timeout");
T(JSON.parse(lines[1]).id == "bingo", lines[1]);
T(JSON.parse(lines[2]).id == "rusty", lines[2]);
diff --git a/share/www/script/test/oauth.js b/share/www/script/test/oauth.js
index 62782853..b439b4db 100644
--- a/share/www/script/test/oauth.js
+++ b/share/www/script/test/oauth.js
@@ -94,17 +94,18 @@ couchTests.oauth = function(debug) {
headers: {"X-Couch-Persist": "false"},
body: JSON.stringify(testadminPassword)
});
- while (true) {
- //loop until the couch server has processed the password
- var xhr = CouchDB.request("GET", "http://" + host + "/_config/admins/testadmin?foo="+i,{
- headers: {
- "Authorization": adminBasicAuthHeaderValue()
- }})
- if (xhr.responseText.indexOf("\"-hashed-") == 0) {
- break;
- }
- console.log("foo:" + xhr.responseText)
- }
+ var i = 0;
+ waitForSuccess(function() {
+ //loop until the couch server has processed the password
+ i += 1;
+ var xhr = CouchDB.request("GET", "http://" + host + "/_config/admins/testadmin?foo="+i,{
+ headers: {
+ "Authorization": adminBasicAuthHeaderValue()
+ }});
+ if (xhr.responseText.indexOf("\"-hashed-") != 0) {
+ throw("still waiting");
+ }
+ }, "wait-for-admin");
CouchDB.newUuids(2); // so we have one to make the salt