-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedea_ttl_test.js
80 lines (71 loc) · 1.9 KB
/
medea_ttl_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var assert = require('assert');
var medea = require('medea');
var ttl = require('../');
describe('MedeaTtl', function() {
var db = ttl(medea());
var dir = __dirname + '/tmp/medea_ttl_test';
before(function(done) {
db.open(dir, done);
});
it('should assign itself to db._ttl', function() {
assert(!!db._ttl);
});
describe('#open', function() {
it('should start the cleanup interval', function() {
assert(!!db._ttl.interval);
});
});
describe('#close', function() {
it('should stop the cleanup interval', function(done) {
db.close(function() {
assert(!!db._ttl.interval);
db.open(dir, done);
});
});
});
describe('#put', function() {
it('should take a ttl parameter', function(done) {
db.put('hello', 'world', 1, function(err, val) {
assert(!err);
done();
});
});
});
describe('#get', function() {
it('should return a fresh value', function(done) {
db.put('hello', 'world', 100, function(err, val) {
setTimeout(function() {
db.get('hello', function(err, val) {
assert(!err);
assert.equal(val, 'world');
done();
});
}, 50);
});
});
it('should not return an expired value', function(done) {
db.put('hello', 'world', 50, function(err, val) {
setTimeout(function() {
db.get('hello', function(err, val) {
assert(!err);
assert(!val);
done();
});
}, 50);
});
});
});
describe('#remove', function() {
it('should auto-expire a ttl value', function(done) {
db.put('hello', 'world', 10000, function(err, val) {
db.remove('hello', function(err) {
db.get('hello', function(err, val) {
assert(!err);
assert(!val);
done();
});
});
});
});
});
});