Skip to content

Commit

Permalink
(pouchdb#4372) Fixing the test for auto compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Genoud committed Feb 4, 2016
1 parent dab8455 commit d803e37
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/integration/test.bulk_docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,11 @@ adapters.forEach(function (adapter) {

var db = new PouchDB(dbs.name, {revs_limit: 2});

// old revisions are always deleted with auto compaction
if (db.auto_compaction) {
return done();
}

var revs = [];
db.put({v: 1}, 'doc').then(function (v1) {
revs.push(v1.rev);
Expand All @@ -1016,6 +1021,8 @@ adapters.forEach(function (adapter) {
// the v2 revision is still in the db
return db.get('doc', {rev: revs[1]});
}).then(function (v2) {
v2.v.should.equal(2);

return db.get('doc', {rev: revs[0]}).then(function (v1) {
// the v1 revision is not in the db anymore
done(new Error('v1 should be missing'));
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/test.merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,55 +75,63 @@ describe('test.merge.js', function () {
it('Merging a path into an empty tree is the path', function () {
merge([], simple, 10).should.deep.equal({
tree: [simple],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});

it('Remerge path into path is reflexive', function () {
merge([simple], simple, 10).should.deep.equal({
tree: [simple],
stemmedRevs: [],
conflicts: 'internal_node'
});
});

it('Merging a path with multiple entries is the path', function () {
merge([], two0, 10).should.deep.equal({
tree: [two0],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});

it('Merging a path with multiple entries is reflexive', function () {
merge([two0], two0, 10).should.deep.equal({
tree: [two0],
stemmedRevs: [],
conflicts: 'internal_node'
});
});

it('Merging a subpath into a path results in the path', function () {
merge([two0], simple, 10).should.deep.equal({
tree: [two0],
stemmedRevs: [],
conflicts: 'internal_node'
});
});

it('Merging a new leaf gives us a new leaf', function () {
merge([two0], newleaf, 10).should.deep.equal({
tree: [withnewleaf],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});

it('Merging a new branch returns a proper tree', function () {
merge([two0], two1, 10).should.deep.equal({
tree: [newbranch],
stemmedRevs: [],
conflicts: 'new_branch'
});
});

it('Order of merging does not affect the resulting tree', function () {
merge([two1], two0, 10).should.deep.equal({
tree: [newbranch],
stemmedRevs: [],
conflicts: 'new_branch'
});
});
Expand All @@ -132,41 +140,47 @@ describe('test.merge.js', function () {
function () {
merge([newbranch], newleaf, 10).should.deep.equal({
tree: [newbranchleaf],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});

it('Merging a deep branch with branches works', function () {
merge([newbranchleaf], newdeepbranch, 10).should.deep.equal({
tree: [newbranchleafbranch],
stemmedRevs: [],
conflicts: 'new_branch'
});
});

it('New information reconnects steming induced conflicts', function () {
merge(stemmedconflicts, withnewleaf, 10).should.deep.equal({
tree: [withnewleaf],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});

it('Simple stemming works', function () {
merge([two0], newleaf, 2).should.deep.equal({
tree: [newleaf],
stemmedRevs: ['1-1'],
conflicts: 'new_leaf'
});
});

it('Merge with stemming works correctly for branches', function () {
merge([newbranchleafbranch], simple, 2).should.deep.equal({
tree: stemmed2,
stemmedRevs: [],
conflicts: 'internal_node'
});
});

it('Merge with stemming to leaves works fine', function () {
merge([newbranchleafbranch], simple, 1).should.deep.equal({
tree: stemmed3,
stemmedRevs: ['1-1', '2-2_0'],
conflicts: 'internal_node'
});
});
Expand All @@ -175,6 +189,7 @@ describe('test.merge.js', function () {
function () {
merge(stemmed3, withnewleaf, 10).should.deep.equal({
tree: partialrecover,
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand Down Expand Up @@ -223,13 +238,15 @@ describe('test.merge.js', function () {
it('The empty tree is the identity for merge.', function () {
merge([], one, 10).should.deep.equal({
tree: [one],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});

it('Merging is reflexive', function () {
merge([one], one, 10).should.deep.equal({
tree: [one],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -239,6 +256,7 @@ describe('test.merge.js', function () {
it('Merging a prefix of a tree with the tree yields the tree.', function () {
merge(twoSibs, one, 10).should.deep.equal({
tree: twoSibs,
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -248,6 +266,7 @@ describe('test.merge.js', function () {
it('Merging a third unrelated branch leads to a conflict.', function () {
merge(twoSibs, three, 10).should.deep.equal({
tree: threeSibs,
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -260,6 +279,7 @@ describe('test.merge.js', function () {
it('Merging two children is still reflexive.', function () {
merge([twoChild], twoChild, 10).should.deep.equal({
tree: [twoChild],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -271,6 +291,7 @@ describe('test.merge.js', function () {
it('Merging a tree to itself is itself.', function () {
merge([twoChildSibs], twoChildSibs, 10).should.deep.equal({
tree: [twoChildSibs],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -284,6 +305,7 @@ describe('test.merge.js', function () {
it('Merging tree of uneven length at node 2.', function () {
merge([twoChild], twoChildSibs, 10).should.deep.equal({
tree: [twoChildPlusSibs],
stemmedRevs: [],
conflicts: 'new_branch'
});
});
Expand All @@ -292,6 +314,7 @@ describe('test.merge.js', function () {
it('Merging a tree with a stem.', function () {
merge([twoChildSibs], stemmed1b, 10).should.deep.equal({
tree: [twoChildSibs],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -306,6 +329,7 @@ describe('test.merge.js', function () {
it('Merging a stem at a deeper level.', function () {
merge([twoChildPlusSibs2], stemmed1bb, 10).should.deep.equal({
tree: [twoChildPlusSibs2],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -318,6 +342,7 @@ describe('test.merge.js', function () {
function () {
merge(stemmedTwoChildSibs2, stemmed1bb, 10).should.deep.equal({
tree: stemmedTwoChildSibs2,
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -326,6 +351,7 @@ describe('test.merge.js', function () {
it("Merging a single tree with a deeper stem.", function () {
merge([twoChild], stemmed1aa, 10).should.deep.equal({
tree: [twoChild],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -334,13 +360,15 @@ describe('test.merge.js', function () {
it('Merging a larger stem.', function () {
merge([twoChild], stemmed1a, 10).should.deep.equal({
tree: [twoChild],
stemmedRevs: [],
conflicts: 'internal_node'
});
});

it('More merging.', function () {
merge([stemmed1a], stemmed1aa, 10).should.deep.equal({
tree: [stemmed1a],
stemmedRevs: [],
conflicts: 'internal_node'
});
});
Expand All @@ -349,13 +377,15 @@ describe('test.merge.js', function () {
it('Merging should create conflicts.', function () {
merge([oneChild], stemmed1aa, 10).should.deep.equal({
tree: [oneChild, stemmed1aa],
stemmedRevs: [],
conflicts: 'internal_node'
});
});

it('Merging should have no conflicts.', function () {
merge([oneChild, stemmed1aa], twoChild, 10).should.deep.equal({
tree: [twoChild],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});
Expand All @@ -379,6 +409,7 @@ describe('test.merge.js', function () {
it('Merging trees with conflicts ought to behave.', function () {
merge([foo], bar, 10).should.deep.equal({
tree: [fooBar],
stemmedRevs: [],
conflicts: 'new_leaf'
});
});
Expand Down

0 comments on commit d803e37

Please sign in to comment.