summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-11-30 03:59:02 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-11-30 03:59:02 +0000
commit85809452290b99a0a00a91dd319b82f51f9f0c4a (patch)
treefa05c1f1b7d7daed9c886e1edc4e1114d42d92ee
parenta37fdafcc65632328599939abf0863d9c02043dd (diff)
work on COUCHDB-582, fixes issues with filtered longpoll requests closing early
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@885329 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/www/script/test/changes.js29
-rw-r--r--src/couchdb/couch_httpd_db.erl2
2 files changed, 27 insertions, 4 deletions
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index bf4a1617..fe18f2d1 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -26,10 +26,10 @@ couchTests.changes = function(debug) {
var resp = JSON.parse(req.responseText);
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);
+
req = CouchDB.request("GET", "/test_suite_db/_changes");
var resp = JSON.parse(req.responseText);
@@ -186,6 +186,7 @@ couchTests.changes = function(debug) {
T(resp.results.length == 0);
db.save({"bop" : "foom"});
+ db.save({"bop" : false});
var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=changes_filter/bop");
var resp = JSON.parse(req.responseText);
@@ -199,6 +200,27 @@ couchTests.changes = function(debug) {
resp = JSON.parse(req.responseText);
T(resp.results.length == 1);
+ if (!is_safari && xhr) { // full test requires parallel connections
+ // filter with longpoll
+ // longpoll filters full history when run without a since seq
+ xhr = CouchDB.newXhr();
+ xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&filter=changes_filter/bop", true);
+ xhr.send("");
+ sleep(100);
+ var resp = JSON.parse(xhr.responseText);
+ T(resp.last_seq == 7);
+ // longpoll waits until a matching change before returning
+ xhr = CouchDB.newXhr();
+ xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=7&filter=changes_filter/bop", true);
+ xhr.send("");
+ db.save({"bop" : ""}); // empty string is falsy
+ var id = db.save({"bop" : "bingo"}).id;
+ sleep(100);
+ var resp = JSON.parse(xhr.responseText);
+ T(resp.last_seq == 9);
+ T(resp.results && resp.results.length > 0 && resp.results[0]["id"] == id, "filter the correct update");
+ }
+
// error conditions
// non-existing design doc
@@ -224,7 +246,7 @@ couchTests.changes = function(debug) {
var req = CouchDB.request("GET",
"/test_suite_db/_changes?filter=changes_filter/bop&style=all_docs");
var resp = JSON.parse(req.responseText);
- TEquals(1, resp.results.length, "should return one result row");
+ TEquals(2, resp.results.length, "should return two rows");
// test for userCtx
run_on_modified_server(
@@ -248,6 +270,7 @@ couchTests.changes = function(debug) {
var docResp = db.save({"user" : "Chris Anderson"});
T(docResp.ok);
+ T(db.ensureFullCommit().ok);
req = CouchDB.request("GET", "/test_suite_db/_changes?filter=changes_filter/userCtx", authOpts);
resp = JSON.parse(req.responseText);
T(resp.results.length == 1, "userCtx");
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 5d23232e..22d18d2f 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -159,7 +159,7 @@ keep_sending_changes(#httpd{user_ctx=UserCtx,path_parts=[DbName|_]}=Req, Resp,
Prepend, ResponseType, Limit, Filter, End),
couch_db:close(Db),
if
- EndSeq > StartSeq, ResponseType == "longpoll" ->
+ Limit > NewLimit, ResponseType == "longpoll" ->
end_sending_changes(Resp, EndSeq, ResponseType);
true ->
case wait_db_updated(Timeout, TimeoutFun) of