From cd8300c001a9949eb0a7f2c1e802b657b6e689f9 Mon Sep 17 00:00:00 2001 From: Arthur Cinader Date: Wed, 22 Feb 2017 22:10:14 -0700 Subject: [PATCH] Fix the redis cache spec to construct the cache with the anticipated ttl make timeout values really really small so our test run fast :). --- spec/RedisCacheAdapter.spec.js | 19 ++++++++++++++----- src/Adapters/Cache/RedisCacheAdapter.js | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/RedisCacheAdapter.spec.js b/spec/RedisCacheAdapter.spec.js index 82e17c22db..9e941eff49 100644 --- a/spec/RedisCacheAdapter.spec.js +++ b/spec/RedisCacheAdapter.spec.js @@ -25,17 +25,26 @@ describe('RedisCacheAdapter', function() { }); it('should expire after ttl', (done) => { - var cache = new RedisCacheAdapter({ - ttl: 100 - }); + var cache = new RedisCacheAdapter(null, 1); cache.put(KEY, VALUE) .then(() => cache.get(KEY)) .then((value) => expect(value).toEqual(VALUE)) - .then(wait.bind(null, 1000)) + .then(wait.bind(null, 2)) .then(() => cache.get(KEY)) .then((value) => expect(value).toEqual(null)) .then(done); - }) + }); + it('should find un-expired records', (done) => { + var cache = new RedisCacheAdapter(null, 5); + + cache.put(KEY, VALUE) + .then(() => cache.get(KEY)) + .then((value) => expect(value).toEqual(VALUE)) + .then(wait.bind(null, 1)) + .then(() => cache.get(KEY)) + .then((value) => expect(value).not.toEqual(null)) + .then(done); + }); }); diff --git a/src/Adapters/Cache/RedisCacheAdapter.js b/src/Adapters/Cache/RedisCacheAdapter.js index bc1de941aa..0347e97260 100644 --- a/src/Adapters/Cache/RedisCacheAdapter.js +++ b/src/Adapters/Cache/RedisCacheAdapter.js @@ -1,7 +1,7 @@ import redis from 'redis'; import logger from '../../logger'; -const DEFAULT_REDIS_TTL = 30000; // 30 seconds in milliseconds +const DEFAULT_REDIS_TTL = 30 * 1000; // 30 seconds in milliseconds function debug() { logger.debug.apply(logger, ['RedisCacheAdapter', ...arguments]);