You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2015/05/24 14:41:21 UTC
couchdb commit: updated refs/heads/master to 6da3b56
Repository: couchdb
Updated Branches:
refs/heads/master 55daa5c6f -> 6da3b560c
add test for _changes?feed=live
PRs for the change:
https://github.com/apache/couchdb/pull/307
https://github.com/apache/couchdb-couch/pull/40
https://github.com/apache/couchdb-chttpd/pull/28
COUCHDB-2237
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/6da3b560
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/6da3b560
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/6da3b560
Branch: refs/heads/master
Commit: 6da3b560cbb5ecba1cf1fb23c34914178abdfec3
Parents: 55daa5c
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Sun Mar 1 15:40:51 2015 +0100
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Sun May 24 14:35:13 2015 +0200
----------------------------------------------------------------------
test/javascript/tests/changes.js | 203 ++++++++++++++++++----------------
1 file changed, 106 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/6da3b560/test/javascript/tests/changes.js
----------------------------------------------------------------------
diff --git a/test/javascript/tests/changes.js b/test/javascript/tests/changes.js
index d5a4236..7877758 100644
--- a/test/javascript/tests/changes.js
+++ b/test/javascript/tests/changes.js
@@ -17,131 +17,140 @@ function jsonp(obj) {
}
couchTests.changes = function(debug) {
- var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"});
- db.deleteDb();
- db.createDb();
+ var db;
if (debug) debugger;
- var req = CouchDB.request("GET", "/test_suite_db/_changes");
- var resp = JSON.parse(req.responseText);
+ // poor man's browser detection
+ var is_safari = false;
+ if (typeof (navigator) == "undefined") {
+ is_safari = true; // For CouchHTTP based runners
+ } else if (navigator.userAgent.match(/AppleWebKit/)) {
+ is_safari = true;
+ }
- T(resp.results.length == 0 && resp.last_seq == 0, "empty db");
- var docFoo = {_id:"foo", bar:1};
- T(db.save(docFoo).ok);
- T(db.ensureFullCommit().ok);
- T(db.open(docFoo._id)._id == docFoo._id);
+ testChanges("live");
+ testChanges("continuous");
+ function testChanges(feed) {
+ db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"});
+ db.deleteDb();
+ db.createDb();
- req = CouchDB.request("GET", "/test_suite_db/_changes");
- var resp = JSON.parse(req.responseText);
+ var req = CouchDB.request("GET", "/test_suite_db/_changes");
+ var resp = JSON.parse(req.responseText);
- T(resp.last_seq == 1);
- T(resp.results.length == 1, "one doc db");
- T(resp.results[0].changes[0].rev == docFoo._rev);
+ T(resp.results.length == 0 && resp.last_seq == 0, "empty db");
+ var docFoo = {_id:"foo", bar:1};
+ T(db.save(docFoo).ok);
+ T(db.ensureFullCommit().ok);
+ T(db.open(docFoo._id)._id == docFoo._id);
- // test with callback
+ req = CouchDB.request("GET", "/test_suite_db/_changes");
+ var resp = JSON.parse(req.responseText);
- run_on_modified_server(
- [{section: "httpd",
- key: "allow_jsonp",
- value: "true"}],
- function() {
- var xhr = CouchDB.request("GET", "/test_suite_db/_changes?callback=jsonp");
- T(xhr.status == 200);
- jsonp_flag = 0;
- eval(xhr.responseText);
- T(jsonp_flag == 1);
- });
+ T(resp.last_seq == 1);
+ T(resp.results.length == 1, "one doc db");
+ T(resp.results[0].changes[0].rev == docFoo._rev);
- req = CouchDB.request("GET", "/test_suite_db/_changes?feed=continuous&timeout=10");
- var lines = req.responseText.split("\n");
- T(JSON.parse(lines[0]).changes[0].rev == docFoo._rev);
- T(JSON.parse(lines[1]).last_seq == 1);
+ // test with callback
- var xhr;
+ run_on_modified_server(
+ [{section: "httpd",
+ key: "allow_jsonp",
+ value: "true"}],
+ function() {
+ var xhr = CouchDB.request("GET", "/test_suite_db/_changes?callback=jsonp");
+ T(xhr.status == 200);
+ jsonp_flag = 0;
+ eval(xhr.responseText);
+ T(jsonp_flag == 1);
+ });
- try {
- xhr = CouchDB.newXhr();
- } catch (err) {
- }
+ req = CouchDB.request("GET", "/test_suite_db/_changes?feed=" + feed + "&timeout=10");
+ var lines = req.responseText.split("\n");
+ T(JSON.parse(lines[0]).changes[0].rev == docFoo._rev);
+ T(JSON.parse(lines[1]).last_seq == 1);
- // poor man's browser detection
- var is_safari = false;
- if(typeof(navigator) == "undefined") {
- is_safari = true; // For CouchHTTP based runners
- } else if(navigator.userAgent.match(/AppleWebKit/)) {
- is_safari = true;
- };
- if (!is_safari && xhr) {
- // Only test the continuous stuff if we have a real XHR object
- // with real async support.
+ var xhr;
- // WebKit (last checked on nightly #47686) does fail on processing
- // the async-request properly while javascript is executed.
+ try {
+ xhr = CouchDB.newXhr();
+ } catch (err) {
+ }
- xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&timeout=500"), true);
- xhr.send("");
+ if (!is_safari && xhr) {
+ // Only test the continuous stuff if we have a real XHR object
+ // with real async support.
- var docBar = {_id:"bar", bar:1};
- db.save(docBar);
+ // WebKit (last checked on nightly #47686) does fail on processing
+ // the async-request properly while javascript is executed.
- var lines, change1, change2;
- waitForSuccess(function() {
- lines = xhr.responseText.split("\n");
- change1 = JSON.parse(lines[0]);
- change2 = JSON.parse(lines[1]);
- if (change2.seq != 2) {
- throw "bad seq, try again";
- }
- return true;
- }, "bar-only");
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=" + feed + "&timeout=500"), true);
+ xhr.send("");
- T(change1.seq == 1);
- T(change1.id == "foo");
+ var docBar = {_id:"bar", bar:1};
+ db.save(docBar);
- T(change2.seq == 2);
- T(change2.id == "bar");
- T(change2.changes[0].rev == docBar._rev);
+ var lines, change1, change2;
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ change1 = JSON.parse(lines[0]);
+ change2 = JSON.parse(lines[1]);
+ if (change2.seq != 2) {
+ throw "bad seq, try again";
+ }
+ return true;
+ }, "bar-only");
+ T(change1.seq == 1);
+ T(change1.id == "foo");
- var docBaz = {_id:"baz", baz:1};
- db.save(docBaz);
+ T(change2.seq == 2);
+ T(change2.id == "bar");
+ T(change2.changes[0].rev == docBar._rev);
- var change3;
- waitForSuccess(function() {
- lines = xhr.responseText.split("\n");
- change3 = JSON.parse(lines[2]);
- if (change3.seq != 3) {
- throw "bad seq, try again";
- }
- return true;
- });
- T(change3.seq == 3);
- T(change3.id == "baz");
- T(change3.changes[0].rev == docBaz._rev);
+ var docBaz = {_id:"baz", baz:1};
+ db.save(docBaz);
+
+ var change3;
+ waitForSuccess(function() {
+ lines = xhr.responseText.split("\n");
+ change3 = JSON.parse(lines[2]);
+ if (change3.seq != 3) {
+ throw "bad seq, try again";
+ }
+ return true;
+ });
+
+ T(change3.seq == 3);
+ T(change3.id == "baz");
+ T(change3.changes[0].rev == docBaz._rev);
- xhr = CouchDB.newXhr();
+ xhr = CouchDB.newXhr();
- //verify the heartbeat newlines are sent
- xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&heartbeat=10&timeout=500"), true);
- xhr.send("");
+ //verify the heartbeat newlines are sent
+ xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=" + feed + "&heartbeat=10&timeout=500"), true);
+ xhr.send("");
- var str;
- waitForSuccess(function() {
- str = xhr.responseText;
- if (str.charAt(str.length - 1) != "\n" || str.charAt(str.length - 2) != "\n") {
- throw("keep waiting");
- }
- return true;
- }, "heartbeat");
+ var str;
+ waitForSuccess(function() {
+ str = xhr.responseText;
+ if (str.charAt(str.length - 1) != "\n" || str.charAt(str.length - 2) != "\n") {
+ throw("keep waiting");
+ }
+ return true;
+ }, "heartbeat");
- T(str.charAt(str.length - 1) == "\n");
- T(str.charAt(str.length - 2) == "\n");
+ T(str.charAt(str.length - 1) == "\n");
+ T(str.charAt(str.length - 2) == "\n");
- // otherwise we'll continue to receive heartbeats forever
- xhr.abort();
+ // otherwise we'll continue to receive heartbeats forever
+ xhr.abort();
+ }
+ }
+ if (!is_safari && xhr) {
// test Server Sent Event (eventsource)
if (!!window.EventSource) {
var source = new EventSource(