Permalink
Browse files

(#585) - Store checkpoint on target.

  • Loading branch information...
1 parent 2764513 commit 60f3cfafc463490bdc8bf733cdd0ca5761aec8ac @stephen-bartell stephen-bartell committed with Mar 29, 2013
Showing with 27 additions and 7 deletions.
  1. +7 −7 src/pouch.replicate.js
  2. +20 −0 tests/test.replication.js
View
@@ -61,8 +61,8 @@ var genReplicationId = function(src, target, opts) {
};
// A checkpoint lets us restart replications from when they were last cancelled
-var fetchCheckpoint = function(src, id, callback) {
- src.get(id, function(err, doc) {
+var fetchCheckpoint = function(target, id, callback) {
+ target.get(id, function(err, doc) {
if (err && err.status === 404) {
callback(null, 0);
} else {
@@ -71,16 +71,16 @@ var fetchCheckpoint = function(src, id, callback) {
});
};
-var writeCheckpoint = function(src, id, checkpoint, callback) {
+var writeCheckpoint = function(target, id, checkpoint, callback) {
var check = {
_id: id,
last_seq: checkpoint
};
- src.get(check._id, function(err, doc) {
+ target.get(check._id, function(err, doc) {
if (doc && doc._rev) {
check._rev = doc._rev;
}
- src.put(check, function(err, doc) {
+ target.put(check, function(err, doc) {
callback();
});
});
@@ -183,13 +183,13 @@ function replicate(src, target, opts, promise) {
function isCompleted() {
if (completed && pending === 0) {
result.end_time = Date.now();
- writeCheckpoint(src, repId, last_seq, function(err, res) {
+ writeCheckpoint(target, repId, last_seq, function(err, res) {
call(opts.complete, err, result);
});
}
}
- fetchCheckpoint(src, repId, function(err, checkpoint) {
+ fetchCheckpoint(target, repId, function(err, checkpoint) {
if (err) {
return call(opts.complete, err);
View
@@ -684,6 +684,26 @@ deletedDocAdapters.map(function(adapters) {
});
});
});
+
+ asyncTest("issue #585 Store checkpoint on target db.", function() {
+ console.info('Starting Test: Local DB contains documents');
+ var docs = [{_id: "a"}, {_id: "b"}];
+ var self = this;
+ initDBPair(this.name, this.remote, function(db, remote) {
+ db.bulkDocs({docs: docs}, {}, function(err, _) {
+ db.replicate.to(self.remote, function(err, result) {
+ ok(result.docs_written === docs.length, 'docs replicated ok');
+ Pouch.destroy(self.remote, function (err, result) {
+ ok(result.ok === true, 'remote was deleted');
+ db.replicate.to(self.remote, function (err, result) {
+ ok(result.docs_written === docs.length, 'docs were written again because target was deleted.');
+ start();
+ });
+ });
+ });
+ });
+ });
+ });
});
// This test only needs to run for one configuration, and it slows stuff

0 comments on commit 60f3cfa

Please sign in to comment.