Skip to content

Instantly share code, notes, and snippets.

@ArtskydJ
Last active March 7, 2016 13:53
Show Gist options
  • Save ArtskydJ/65ebbd9cdbcdea9f091e to your computer and use it in GitHub Desktop.
Save ArtskydJ/65ebbd9cdbcdea9f091e to your computer and use it in GitHub Desktop.
level-ttl and level-sublevel confliction
var test = require('tap').test
var sublevel = require('level-sublevel')
//var Levelup = require('level-mem')
var Levelup = require('level')
var ttl = require('level-ttl')
test('level-ttl and sublevel on the same db', function(t) {
var db = Levelup('newThang')
t.plan(5)
var dbWithSublevel = sublevel(db)
var subDb = dbWithSublevel.sublevel('something')
var ttlDb = ttl(subDb, {
checkFrequency: 50
})
var dbOptions = {
keyEncoding: 'utf8',
valueEncoding: 'utf8',
ttl: 500
}
ttlDb.put('key', 'value', dbOptions, function(err) {
t.notOk(err, 'No error on the put')
})
setTimeout(function() {
ttlDb.get('key', function(err, value) {
t.notOk(err)
t.equal('value', value, 'Value is there and correct')
})
}, 200)
setTimeout(function() {
ttlDb.get('key', function(err, value) {
t.ok(err)
t.ok(err.notFound, 'Value is not found after 1s')
t.end()
})
}, 1000)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment