summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-05-13 18:27:11 +0000
committerDamien F. Katz <damien@apache.org>2009-05-13 18:27:11 +0000
commitc044a331eda306bac2383aecb9996f987029dba0 (patch)
treec0d180426d5c403829eaa4557cb6d80772c9ad26
parent26694f7abd4a24a5dddc35de7af770da44923c91 (diff)
Adding testing for GET /_changes?continuous=true by adding a GET /_sleep?time=Msecs call, which allows the browser to process the waiting data on the other async XHR request.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@774474 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--etc/couchdb/default.ini.tpl.in1
-rw-r--r--share/www/script/test/changes.js76
-rw-r--r--src/couchdb/couch_httpd_misc_handlers.erl8
-rw-r--r--src/couchdb/couch_query_servers.erl2
4 files changed, 75 insertions, 12 deletions
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index 3caaf597..02aea96b 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -60,6 +60,7 @@ _uuids = {couch_httpd_misc_handlers, handle_uuids_req}
_restart = {couch_httpd_misc_handlers, handle_restart_req}
_stats = {couch_httpd_stats_handlers, handle_stats_req}
_log = {couch_httpd_misc_handlers, handle_log_req}
+_sleep = {couch_httpd_misc_handlers, handle_sleep_req}
[httpd_db_handlers]
_compact = {couch_httpd_db, handle_compact_req}
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index fef2bcca..fe8a1cd5 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -10,29 +10,85 @@
// License for the specific language governing permissions and limitations under
// the License.
+
couchTests.changes = function(debug) {
var db = new CouchDB("test_suite_db");
db.deleteDb();
db.createDb();
if (debug) debugger;
-
- var req = CouchDB.newXhr();
-
- req.open("GET", "/test_suite_db/_changes", false);
- req.send("");
+ var req = CouchDB.request("GET", "/test_suite_db/_changes");
var resp = JSON.parse(req.responseText);
T(resp.results.length == 0 && resp.last_seq==0)
- var doc = {_id:"foo", bar:1};
- db.save(doc);
+ var docFoo = {_id:"foo", bar:1};
+ db.save(docFoo);
- req.open("GET", "/test_suite_db/_changes", false);
- req.send("");
+ req = CouchDB.request("GET", "/test_suite_db/_changes");
var resp = JSON.parse(req.responseText);
T(resp.results.length == 1 && resp.last_seq==1)
- T(resp.results[0].changes[0].rev == doc._rev)
+ T(resp.results[0].changes[0].rev == docFoo._rev)
+
+ var xhr;
+
+ try {
+ xhr = CouchDB.newXhr();
+ } catch (err) {
+ }
+
+ if (xhr) {
+ // Only test the continuous stuff if we have a real XHR object
+ // with real async support.
+
+ var sleep = function(msecs) {
+ // by making a slow sync request, weallows the waiting XHR request data
+ // to be received.
+ var req = CouchDB.request("GET", "/_sleep?time=" + msecs);
+ T(JSON.parse(req.responseText).ok == true);
+ }
+
+ var parse_changes_line = function(line) {
+ if (line.charAt(line.length-1) == ",") {
+ line = line.substring(0, line.length-1);
+ }
+ return JSON.parse(line);
+ }
+
+ xhr.open("GET", "/test_suite_db/_changes?continuous=true", true);
+ xhr.send("");
+
+ var docBar = {_id:"bar", bar:1};
+ db.save(docBar);
+
+ sleep(100);
+ var lines = xhr.responseText.split("\n");
+
+ T(lines[0]='{"results":[');
+
+ var change = parse_changes_line(lines[1]);
+
+ T(change.seq == 1)
+ T(change.id == "foo")
+
+ change = parse_changes_line(lines[2]);
+
+ T(change.seq == 2)
+ T(change.id == "bar")
+ T(change.changes[0].rev == docBar._rev)
+
+ var docBaz = {_id:"baz", baz:1};
+ db.save(docBaz);
+
+ sleep(100);
+ var lines = xhr.responseText.split("\n");
+
+ change = parse_changes_line(lines[3]);
+
+ T(change.seq == 3);
+ T(change.id == "baz");
+ T(change.changes[0].rev == docBaz._rev);
+ }
};
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
index 5daeeeea..36dfa0ac 100644
--- a/src/couchdb/couch_httpd_misc_handlers.erl
+++ b/src/couchdb/couch_httpd_misc_handlers.erl
@@ -15,7 +15,7 @@
-export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2,
handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1,
handle_uuids_req/1,handle_config_req/1,handle_log_req/1,
- handle_task_status_req/1]).
+ handle_task_status_req/1,handle_sleep_req/1]).
-export([increment_update_seq_req/2]).
@@ -56,6 +56,12 @@ handle_utils_dir_req(#httpd{method='GET'}=Req, DocumentRoot) ->
handle_utils_dir_req(Req, _) ->
send_method_not_allowed(Req, "GET,HEAD").
+handle_sleep_req(#httpd{method='GET'}=Req) ->
+ Time = list_to_integer(couch_httpd:qs_value(Req, "time")),
+ receive snicklefart -> ok after Time -> ok end,
+ send_json(Req, {[{ok, true}]});
+handle_sleep_req(Req) ->
+ send_method_not_allowed(Req, "GET,HEAD").
handle_all_dbs_req(#httpd{method='GET'}=Req) ->
{ok, DbNames} = couch_server:all_databases(),
diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl
index 734baade..7c82abe7 100644
--- a/src/couchdb/couch_query_servers.erl
+++ b/src/couchdb/couch_query_servers.erl
@@ -278,7 +278,7 @@ handle_info({'EXIT', Pid, Status}, {Langs, PidLangs, Pids, InUse}) ->
[{Pid, Lang}] ->
case Status of
normal -> ok;
- _ -> ?LOG_DEBUG("Linked process died abnromally: ~p (reason: ~p)", [Pid, Status])
+ _ -> ?LOG_DEBUG("Linked process died abnormally: ~p (reason: ~p)", [Pid, Status])
end,
{ok, {
Langs,