Permalink
Browse files

Merge pull request #31 from hsch/master

Adapted tests to Node 0.4.12 and CouchDB 1.0.1 (Ubuntu 11.10 default)
  • Loading branch information...
felixge committed Nov 1, 2011
2 parents 9585d57 + 0a21d99 commit e5a4862c728585474c64750c86cc93543fa2a564
Showing with 65 additions and 14 deletions.
  1. +3 −0 README.md
  2. +6 −1 lib/couchdb.js
  3. +1 −1 test/common.js
  4. +44 −12 test/test-client.js
  5. +11 −0 test/test-db.js
View
@@ -255,6 +255,9 @@ Wrapper for [GET /db-name/\_all\_docs](http://wiki.apache.org/couchdb/HTTP_Docum
Wrapper for [GET /db-name/\_all\_docs\_by\_seq](http://wiki.apache.org/couchdb/HTTP_Document_API#all_docs_by_seq).
+Replaced by [GET /db-name/\_changes](http://wiki.apache.org/couchdb/HTTP_database_API#Changes) as of CouchDB 0.11.
+Consider using `db.changes` or `db.changesStream`.
+
### db.compact([design])
Wrapper for [POST /db-name/\_compact/design-name](http://wiki.apache.org/couchdb/HTTP_view_API#View_Compaction). `design` provides the name of the design to invoke compact for, otherwise the whole db is used.
View
@@ -619,7 +619,12 @@ Db.prototype.changesStream = function(query, options) {
});
stream.close = function() {
- return client.destroy();
+ if (request.abort) {
+ return request.abort();
+ }
+ else {
+ return client.destroy();
+ }
};
return stream;
View
@@ -11,4 +11,4 @@ global.checkCallbacks = function(callbacks) {
};
// Provide a port/host here if your local db has a non-default setup
-GLOBAL.client = couchdb.createClient();
+GLOBAL.client = couchdb.createClient(undefined, undefined, undefined, undefined, 20);
View
@@ -1,5 +1,15 @@
require('./common');
+/*
+ * Note: If this test fails (specifically the replication part) with an
+ * Erlang stacktrace, this may be due to
+ *
+ * https://issues.apache.org/jira/browse/COUCHDB-1221
+ *
+ * I was able to work around this by restarting CouchDB.
+ * ~~ https://github.com/hsch/
+ */
+
var
DB_NAME = 'node-couchdb-test',
DB_NAME2 = 'node-couchdb-test-mirror',
@@ -14,6 +24,7 @@ var
E: false,
F: false,
G: false,
+ H: false
};
// Get a list of all databases
@@ -59,24 +70,45 @@ client
// Lets create two dbs to test replication
var db = client.db(DB_NAME);
-db.remove();
-db.create();
-db.saveDoc(TEST_ID, TEST_DOC);
-
var db2 = client.db(DB_NAME2);
-db2.remove();
-db2.create();
-client
- .replicate(DB_NAME, DB_NAME2, function(er, r) {
- if (er) throw new Error(JSON.stringify(er));
- callbacks.F = true;
- assert.ok('session_id' in r);
- });
+// Here's how we'll actually replicate later.
+var replicate = function() {
+ client
+ .replicate(DB_NAME, DB_NAME2, function(er, r) {
+ if (er) {
+ if (er.reason && er.reason.indexOf('erlang') > 0) {
+ console.error("---------------------------------------------------------------------------------");
+ console.error(" Test failed. Possibly due to https://issues.apache.org/jira/browse/COUCHDB-1221");
+ console.error(" Try restarting CouchDB for a quick fix.");
+ console.error("---------------------------------------------------------------------------------");
+ }
+ throw new Error(JSON.stringify(er));
+ }
+ callbacks.F = true;
+ assert.ok('session_id' in r);
+ });
+};
+// Create first db, save document, create second db, then
+// replicate. And all that in a well-defined order.
+db.remove(function() {
+ db.create(function() {
+ db.saveDoc(TEST_ID, TEST_DOC, function() {
+ db2.remove(function() {
+ db2.create(function() {
+ replicate();
+ });
+ });
+ });
+ });
+});
// Test connecting to a port where there is no couch
var client2 = couchdb.createClient(3921);
+client2._addClientListener('error', function(er) {
+ if (er) callbacks.H = true;
+});
client2
.uuids(function(er, r) {
if (er) callbacks.G = true;
View
@@ -130,6 +130,17 @@ db
// Test allDocsBySeq
db
.allDocsBySeq(function(er, r) {
+ /*
+ * An error here is perfectly valid as of CouchDB 0.11. The _all_docs_by_seq API
+ * has been replaced by _changes.
+ */
+ if (er && er.error == 'not_found' && er.reason == 'missing') {
+ callbacks.L = true;
+ return;
+ }
+ /*
+ * If there is as an error different from 404, it may still be a problem.
+ */
if (er) throw new Error(JSON.stringify(er));
callbacks.L = true;
assert.ok('rows' in r);

0 comments on commit e5a4862

Please sign in to comment.