summaryrefslogtreecommitdiff
path: root/share/www/script
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2010-03-21 20:20:52 +0000
committerJan Lehnardt <jan@apache.org>2010-03-21 20:20:52 +0000
commit61635f00be831a8cb52d5d93a8fbc619e87a73e7 (patch)
treebbdb014177d2ce8cb95d6a4643ef6e6f9c6a97e7 /share/www/script
parentd0d251175a2800b44ef337663c04d7cfc207d711 (diff)
Test for a regression with doc-id replication.
Patch by Filipe Manana. Closes COUCHDB-703. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@925883 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script')
-rw-r--r--share/www/script/test/replication.js100
1 files changed, 75 insertions, 25 deletions
diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js
index c6f6ff61..c03ce430 100644
--- a/share/www/script/test/replication.js
+++ b/share/www/script/test/replication.js
@@ -329,12 +329,25 @@ couchTests.replication = function(debug) {
dbA.deleteDb();
dbA.createDb();
- dbB.deleteDb();
- dbB.createDb();
- T(dbA.save({_id:"foo1",value:"a"}).ok);
- T(dbA.save({_id:"foo2",value:"b"}).ok);
- T(dbA.save({_id:"foo3",value:"c"}).ok);
+ var all_docs = [
+ {
+ _id: "foo1",
+ value: "a"
+ },
+ {
+ _id: "foo2",
+ value: "b"
+ },
+ {
+ _id: "foo3",
+ value: "c"
+ }
+ ];
+
+ for (var i = 0; i < all_docs.length; i++) {
+ T(dbA.save(all_docs[i]).ok);
+ }
var dbPairs = [
{source:"test_suite_rep_docs_db_a",
@@ -347,34 +360,71 @@ couchTests.replication = function(debug) {
target:"http://" + host + "/test_suite_rep_docs_db_b"}
];
+ var target_doc_ids = [
+ ["foo1", "foo3", "foo666"],
+ ["foo1", "foo666"],
+ ["foo666", "foo2"],
+ ["foo2", "foo9999", "foo1"]
+ ];
+
for (var i = 0; i < dbPairs.length; i++) {
- var dbA = dbPairs[i].source;
- var dbB = dbPairs[i].target;
+ var src_db = dbPairs[i].source;
+ var tgt_db = dbPairs[i].target;
- var repResult = CouchDB.replicate(dbA, dbB, {
- body: {"doc_ids": ["foo1", "foo3", "foo666"]}
- });
+ for (var j = 0; j < target_doc_ids.length; j++) {
+ var doc_ids = target_doc_ids[j];
+ var valid_doc_ids = [];
+ var invalid_doc_ids = [];
- T(repResult.ok);
- T(repResult.docs_written === 2);
- T(repResult.docs_read === 2);
- T(repResult.doc_write_failures === 0);
+ $.each(doc_ids, function(index, id) {
+ var found = false;
- dbB = new CouchDB("test_suite_rep_docs_db_b");
+ for (var k = 0; k < all_docs.length; k++) {
+ var doc = all_docs[k];
- var docFoo1 = dbB.open("foo1");
- T(docFoo1 !== null);
- T(docFoo1.value === "a");
+ if (id === doc._id) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ valid_doc_ids.push(id);
+ } else {
+ invalid_doc_ids.push(id);
+ }
+ });
- var docFoo2 = dbB.open("foo2");
- T(docFoo2 === null);
+ dbB.deleteDb();
+ dbB.createDb();
- var docFoo3 = dbB.open("foo3");
- T(docFoo3 !== null);
- T(docFoo3.value === "c");
+ var repResult = CouchDB.replicate(src_db, tgt_db, {
+ body: {"doc_ids": doc_ids}
+ });
- var docFoo666 = dbB.open("foo666");
- T(docFoo666 === null);
+ T(repResult.ok);
+ T(repResult.docs_written === valid_doc_ids.length);
+ T(repResult.docs_read === valid_doc_ids.length);
+ T(repResult.doc_write_failures === 0);
+
+ for (var k = 0; k < all_docs.length; k++) {
+ var doc = all_docs[k];
+ var tgt_doc = dbB.open(doc._id);
+
+ if ($.inArray(doc._id, doc_ids) >= 0) {
+ T(tgt_doc !== null);
+ T(tgt_doc.value === doc.value);
+ } else {
+ T(tgt_doc === null);
+ }
+ }
+
+ for (var k = 0; k < invalid_doc_ids.length; k++) {
+ var tgt_doc = dbB.open(invalid_doc_ids[k]);
+
+ T(tgt_doc === null);
+ }
+ }
}
// test filtered replication