Created
October 17, 2014 20:49
-
-
Save ahizzle/eb34a847016f2bf89cf8 to your computer and use it in GitHub Desktop.
test case for #2888
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| var util = require('util'); | |
| var adapter = 'leveldb'; | |
| describe('test.leveldb.js-' + adapter, function () { | |
| var dbs = {}; | |
| beforeEach(function (done) { | |
| dbs.name = testUtils.adapterUrl(adapter, 'bugtest'); | |
| done(); | |
| }); | |
| it('Increments rev properly for multiple creation/deletion of doc with same id', function (done) { | |
| var db = new PouchDB(dbs.name); | |
| var id = 'foobar'; | |
| var d = { _id: id }; | |
| //db.get(id, {revs: false, open_revs: 'all'}).then(function(doc) { | |
| db.get(id).then(function(doc) { | |
| console.log('Existing doc for id is: '+util.inspect(doc)); | |
| }).catch(function(err) { | |
| console.log('Doc is missing, as it should be'); | |
| }); | |
| db.put(d).then(function() { | |
| return db.get(id, {revs: true, open_revs: 'all'}); | |
| }).then(function(doc) { | |
| //console.log('Wrote doc: '+util.inspect(doc)); | |
| d._rev = doc[0].ok._rev; | |
| console.log('write 1, rev = '+d._rev); | |
| d._rev[0].should.equal('1'); | |
| return db.remove(d); | |
| }).then(function(doc) { | |
| console.log('Removed doc: '+util.inspect(doc)); | |
| d._rev = doc.rev; | |
| console.log('del 1, rev = '+d._rev); | |
| d._rev[0].should.equal('2'); | |
| return db.put(d); | |
| }).then(function(doc) { | |
| console.log('Re-wrote the doc'); | |
| return db.get(id, {revs: true, open_revs: 'all'}); | |
| }).then(function(doc) { | |
| //console.log('3 doc is '+util.inspect(doc)); | |
| d._rev = doc[0].ok._rev; | |
| console.log('write 2, rev = '+d._rev); | |
| d._rev[0].should.equal('3'); | |
| //console.log('Removing '+util.inspect(d)); | |
| return db.remove(d); | |
| }).then(function(doc) { | |
| //console.log('4 doc is '+util.inspect(doc)); | |
| d._rev = doc.rev; | |
| console.log('del 2, rev = '+d._rev); | |
| d._rev[0].should.equal('4'); | |
| done(); | |
| }); | |
| }); | |
| it('Should start the rev count where it left off, but instead re-starts at 1', function (done) { | |
| var db = new PouchDB(dbs.name); | |
| var id = 'foobar'; | |
| var d = { _id: id }; | |
| db.get(id).then(function(doc) { | |
| console.log('Existing doc for id is: '+util.inspect(doc)); | |
| console.log('ERROR: There should not be a pre-existing doc!'); | |
| }).catch(function(err) { | |
| console.log('Doc is missing, as it should be'); | |
| });; | |
| db.put(d).then(function() { | |
| return db.get(id, {revs: true, open_revs: 'all'}); | |
| }).then(function(doc) { | |
| //console.log('1 doc is '+util.inspect(doc)); | |
| d._rev = doc[0].ok._rev; | |
| console.log('write 3, rev = '+d._rev+' <<<< HUH? '); | |
| //d._rev[0].should.equal('5'); | |
| return db.remove(d); | |
| }).then(function(doc) { | |
| //console.log('2 doc is '+util.inspect(doc)); | |
| d._rev = doc.rev; | |
| console.log('del 3, rev = '+d._rev); | |
| return db.put(d); | |
| }).then(function(doc) { | |
| return db.get(id, {revs: true, open_revs: 'all'}); | |
| }).then(function(doc) { | |
| //console.log('3 doc is '+util.inspect(doc)); | |
| d._rev = doc[0].ok._rev; | |
| console.log('write 4, rev = '+d._rev); | |
| console.log('Removing '+util.inspect(d)); | |
| return db.remove(d); | |
| }).then(function(doc) { | |
| console.log('Remove returned this: '+util.inspect(doc)); | |
| d._rev = doc.rev; | |
| console.log('del 4, rev = '+d._rev); | |
| return db.get(id); | |
| }).then(function(doc) { | |
| console.log('The get should have failed, or return tombstone: '+util.inspect(doc)); | |
| done(); | |
| }); | |
| }); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been running this from the tests dir directly like this:
../node_modules/.bin/mocha --timeout=2000 --require=./node.setup.js --reporter=spec test.leveldb.jsAnd to test the weirdness across persistent DB instances, edit node.setup.js and uncomment the exec('rm -r') line.
If you see the test case hang the second time around, you need apache/pouchdb#2885 too.