<commit_before>var remote = {
  host: 'localhost:1234'
};

module('replication', {
  setup : function () {
    this.name = 'test_suite_db';
    this.remote = 'http://' + remote.host + '/test_suite_db/';
  }
});

var docs = [
  {_id: "0", integer: 0, string: '0'},
  {_id: "1", integer: 1, string: '1'},
  {_id: "2", integer: 2, string: '2'}
];

asyncTest("Test basic pull replication", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.bulkDocs({docs: docs}, {}, function(err, results) {
      db.replicate.from(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written = docs.length, 'correct # docs written');
        start();
      });
    });
  });
});

asyncTest("Local DB contains documents", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.bulkDocs({docs: docs}, {}, function(err, _) {
      db.bulkDocs({docs: docs}, {}, function(err, _) {
        db.replicate.from(self.remote, function(err, _) {
          db.allDocs(function(err, result) {
            ok(result.rows.length === docs.length, 'correct # docs exist');
            start();
          });
        });
      });
    });
  });
});

asyncTest("Test basic push replication", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    db.bulkDocs({docs: docs}, {}, function(err, results) {
      db.replicate.to(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written === docs.length, 'correct # docs written');
        start();
      });
    });
  });
});

asyncTest("Test basic push replication take 2", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    db.bulkDocs({docs: docs}, {}, function(err, _) {
      db.replicate.to(self.remote, function(err, _) {
        remote.allDocs(function(err, result) {
          ok(result.rows.length === docs.length, 'correct # docs written');
          start();
        });
      });
    });
  });
});

asyncTest("Test checkpoint", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.bulkDocs({docs: docs}, {}, function(err, results) {
      db.replicate.from(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written === docs.length, 'correct # docs written');
        db.replicate.from(self.remote, function(err, result) {
          ok(result.ok, 'replication was ok');
          ok(result.docs_written === 0, 'correct # docs written');
          ok(result.docs_read === 0, 'no docs read');
          start();
        });
      });
    });
  });
});

// CouchDB will not generate a conflict here, it uses a deteministic<commit_msg>added test for replication issue<commit_after>var remote = {
  host: 'localhost:1234'
};

module('replication', {
  setup : function () {
    this.name = 'test_suite_db';
    this.remote = 'http://' + remote.host + '/test_suite_db/';
  }
});

var docs = [
  {_id: "0", integer: 0, string: '0'},
  {_id: "1", integer: 1, string: '1'},
  {_id: "2", integer: 2, string: '2'}
];

asyncTest("Test basic pull replication", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.bulkDocs({docs: docs}, {}, function(err, results) {
      db.replicate.from(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written = docs.length, 'correct # docs written');
        start();
      });
    });
  });
});

asyncTest("Local DB contains documents", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.bulkDocs({docs: docs}, {}, function(err, _) {
      db.bulkDocs({docs: docs}, {}, function(err, _) {
        db.replicate.from(self.remote, function(err, _) {
          db.allDocs(function(err, result) {
            ok(result.rows.length === docs.length, 'correct # docs exist');
            start();
          });
        });
      });
    });
  });
});

asyncTest("Test basic push replication", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    db.bulkDocs({docs: docs}, {}, function(err, results) {
      db.replicate.to(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written === docs.length, 'correct # docs written');
        start();
      });
    });
  });
});

asyncTest("Test basic push replication take 2", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    db.bulkDocs({docs: docs}, {}, function(err, _) {
      db.replicate.to(self.remote, function(err, _) {
        remote.allDocs(function(err, result) {
          ok(result.rows.length === docs.length, 'correct # docs written');
          start();
        });
      });
    });
  });
});

asyncTest("Test checkpoint", function() {
  var self = this;
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.bulkDocs({docs: docs}, {}, function(err, results) {
      db.replicate.from(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written === docs.length, 'correct # docs written');
        db.replicate.from(self.remote, function(err, result) {
          ok(result.ok, 'replication was ok');
          ok(result.docs_written === 0, 'correct # docs written');
          ok(result.docs_read === 0, 'no docs read');
          start();
        });
      });
    });
  });
});

asyncTest("Test checkpoint 2", function() {
  var self = this;
  var doc = {_id: "3", count: 0};
  initDBPair(this.name, this.remote, function(db, remote) {
    remote.put(doc, {}, function(err, results) {
      db.replicate.from(self.remote, function(err, result) {
        ok(result.ok, 'replication was ok');
        ok(result.docs_written === docs.length, 'correct # docs written');
        doc._rev = results.rev;
        doc.count++;
        remote.put(doc, {}, function(err, results) {
          doc._rev = results.rev;
          doc.count++;
          remote.put(doc, {}, function(err, results) {
            db.replicate.from(self.remote, function(err, result) {
              ok(result.ok, 'replication was ok');
              ok(result.docs_written === 1, 'correct # docs written');
              start();
            });
          });
        });
      });
    });
  });
});

// CouchDB will not generate a conflict here, it uses a deteministic
{'fraction_non_alphanumeric': 0.17925813777441332, 'fraction_numerical': 0.005450416351249054, 'mean_word_length': 2.766248574686431, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1847855', 'n_tokens_mistral': 2183, 'n_tokens_neox': 2119, 'n_words': 462}