@@ -1,4 +1,5 @@
|
||||
const RedisCacheAdapter = require('../lib/Adapters/Cache/RedisCacheAdapter').default;
|
||||
const RedisCacheAdapter = require('../lib/Adapters/Cache/RedisCacheAdapter')
|
||||
.default;
|
||||
/*
|
||||
To run this test part of the complete suite
|
||||
set PARSE_SERVER_TEST_CACHE='redis'
|
||||
@@ -13,44 +14,47 @@ describe_only(() => {
|
||||
function wait(sleep) {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(resolve, sleep);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
it('should get/set/clear', (done) => {
|
||||
it('should get/set/clear', done => {
|
||||
const cache = new RedisCacheAdapter({
|
||||
ttl: NaN
|
||||
ttl: NaN,
|
||||
});
|
||||
|
||||
cache.put(KEY, VALUE)
|
||||
cache
|
||||
.put(KEY, VALUE)
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(VALUE))
|
||||
.then(value => expect(value).toEqual(VALUE))
|
||||
.then(() => cache.clear())
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(null))
|
||||
.then(value => expect(value).toEqual(null))
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should expire after ttl', (done) => {
|
||||
it('should expire after ttl', done => {
|
||||
const cache = new RedisCacheAdapter(null, 1);
|
||||
|
||||
cache.put(KEY, VALUE)
|
||||
cache
|
||||
.put(KEY, VALUE)
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(VALUE))
|
||||
.then(value => expect(value).toEqual(VALUE))
|
||||
.then(wait.bind(null, 2))
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(null))
|
||||
.then(value => expect(value).toEqual(null))
|
||||
.then(done);
|
||||
});
|
||||
|
||||
it('should find un-expired records', (done) => {
|
||||
it('should find un-expired records', done => {
|
||||
const cache = new RedisCacheAdapter(null, 5);
|
||||
|
||||
cache.put(KEY, VALUE)
|
||||
cache
|
||||
.put(KEY, VALUE)
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).toEqual(VALUE))
|
||||
.then(value => expect(value).toEqual(VALUE))
|
||||
.then(wait.bind(null, 1))
|
||||
.then(() => cache.get(KEY))
|
||||
.then((value) => expect(value).not.toEqual(null))
|
||||
.then(value => expect(value).not.toEqual(null))
|
||||
.then(done);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user