From 571edb05e32a2ae70ca7e1b1086ba937d2941a66 Mon Sep 17 00:00:00 2001 From: Robert Newson Date: Tue, 17 May 2011 19:13:42 +0000 Subject: port Filipe's fix and test for COUCHDB-885 to 1.1.x git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1104475 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/replication.js | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'share/www/script/test/replication.js') diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index 7f92891e..bde4ad11 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -785,6 +785,62 @@ couchTests.replication = function(debug) { TEquals('string', typeof repResult._local_id); + // COUCHDB-885 - push replication of a doc with attachment causes a + // conflict in the target. + dbA = new CouchDB("test_suite_db_a"); + dbB = new CouchDB("test_suite_db_b"); + + dbA.deleteDb(); + dbA.createDb(); + dbB.deleteDb(); + dbB.createDb(); + + var doc = { + _id: "doc1" + }; + TEquals(true, dbA.save(doc).ok); + + repResult = CouchDB.replicate( + dbA.name, + CouchDB.protocol + host + "/" + dbB.name + ); + TEquals(true, repResult.ok); + TEquals(true, repResult.history instanceof Array); + TEquals(1, repResult.history.length); + TEquals(1, repResult.history[0].docs_written); + TEquals(1, repResult.history[0].docs_read); + TEquals(0, repResult.history[0].doc_write_failures); + + doc["_attachments"] = { + "hello.txt": { + "content_type": "text/plain", + "data": "aGVsbG8gd29ybGQ=" // base64:encode("hello world") + }, + "foo.dat": { + "content_type": "not/compressible", + "data": "aSBhbSBub3QgZ3ppcGVk" // base64:encode("i am not gziped") + } + }; + + TEquals(true, dbA.save(doc).ok); + repResult = CouchDB.replicate( + dbA.name, + CouchDB.protocol + host + "/" + dbB.name + ); + TEquals(true, repResult.ok); + TEquals(true, repResult.history instanceof Array); + TEquals(2, repResult.history.length); + TEquals(1, repResult.history[0].docs_written); + TEquals(1, repResult.history[0].docs_read); + TEquals(0, repResult.history[0].doc_write_failures); + + var copy = dbB.open(doc._id, {conflicts: true, deleted_conflicts: true}); + T(copy !== null); + TEquals("undefined", typeof copy._conflicts); + TEquals("undefined", typeof copy._deleted_conflicts); + // end of test for COUCHDB-885 + + // cleanup dbA.deleteDb(); dbB.deleteDb(); -- cgit v1.2.3 From 589a5043e34c3bb98eb97b780fd015e0d1296152 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Tue, 17 May 2011 19:18:57 +0000 Subject: Added extra assertions to the test for COUCHDB-885 This is to verify the attachments really exist in the target and have the right data and metadata. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1104478 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/replication.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'share/www/script/test/replication.js') diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index bde4ad11..ea6713e8 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -838,6 +838,12 @@ couchTests.replication = function(debug) { T(copy !== null); TEquals("undefined", typeof copy._conflicts); TEquals("undefined", typeof copy._deleted_conflicts); + TEquals("text/plain", copy._attachments["hello.txt"]["content_type"]); + TEquals("aGVsbG8gd29ybGQ=", copy._attachments["hello.txt"]["data"]); + TEquals("gzip", copy._attachments["hello.txt"]["encoding"]); + TEquals("not/compressible", copy._attachments["foo.dat"]["content_type"]); + TEquals("aSBhbSBub3QgZ3ppcGVk", copy._attachments["foo.dat"]["data"]); + TEquals("undefined", typeof copy._attachments["foo.dat"]["encoding"]); // end of test for COUCHDB-885 -- cgit v1.2.3 From 61c777b873004f795060b5f432cce02402bdf026 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Tue, 17 May 2011 19:24:56 +0000 Subject: Add missing doc open option to the test for COUCHDB-885 These were forgotten when backporting the attachment related assertions from 1.0.x. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1104481 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/replication.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'share/www/script/test/replication.js') diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index ea6713e8..a08c0b66 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -834,7 +834,9 @@ couchTests.replication = function(debug) { TEquals(1, repResult.history[0].docs_read); TEquals(0, repResult.history[0].doc_write_failures); - var copy = dbB.open(doc._id, {conflicts: true, deleted_conflicts: true}); + var copy = dbB.open(doc._id, { + conflicts: true, deleted_conflicts: true, attachments: true, + att_encoding_info: true}); T(copy !== null); TEquals("undefined", typeof copy._conflicts); TEquals("undefined", typeof copy._deleted_conflicts); -- cgit v1.2.3 From a9ce63984c13d126f633a6ab8a243910feac6bc8 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Wed, 18 May 2011 10:54:39 +0000 Subject: Avoid assertion failure in replication.js due to timing issues git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1124185 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/replication.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'share/www/script/test/replication.js') diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index a08c0b66..5e85847e 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -12,6 +12,20 @@ couchTests.replication = function(debug) { if (debug) debugger; + + function waitForSeq(sourceDb, targetDb) { + var targetSeq, + sourceSeq = sourceDb.info().update_seq, + t0 = new Date(), + t1, + ms = 3000; + + do { + targetSeq = targetDb.info().update_seq; + t1 = new Date(); + } while (((t1 - t0) <= ms) && targetSeq < sourceSeq); + } + var host = CouchDB.host; var dbPairs = [ {source:"test_suite_db_a", @@ -768,6 +782,7 @@ couchTests.replication = function(debug) { var tasksAfter = JSON.parse(xhr.responseText); TEquals(tasks.length, tasksAfter.length); + waitForSeq(dbA, dbB); T(dbB.open("30") !== null); repResult = CouchDB.replicate( -- cgit v1.2.3