diff options
Diffstat (limited to 'share/www/script/test/replication.js')
| -rw-r--r-- | share/www/script/test/replication.js | 79 | 
1 files changed, 79 insertions, 0 deletions
| diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index 7f92891e..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( @@ -785,6 +800,70 @@ 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, attachments: true, +    att_encoding_info: true}); +  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 + +    // cleanup    dbA.deleteDb();    dbB.deleteDb(); | 
