after(() => { LoggerHandler.prototype.info.restore() LoggerHandler.prototype.warn.restore() LoggerHandler.prototype.error.restore() LoggerHandler.prototype.debug.restore() redis.createClient.restore() })
.end(function (err, res3) { if (err) return done(err); redis.createClient.restore(); res1.body.results.length.should.eql(2); res3.body.results.length.should.eql(3); res3.text.should.not.equal(res1.text); app.stop(function(){}); done(); });
.end(function (err, res2) { if (err) return done(err); redis.createClient.restore(); res2.headers['x-cache'].should.eql('MISS'); res2.headers['x-cache-lookup'].should.eql('MISS'); app.stop(function(){}); done(); });
.end(function (err, res) { if (err) return done(err); spy.called.should.eql(true); spy.args[0][0].should.eql(cacheKey); c.redisClient.exists.restore(); redis.createClient.restore(); app.stop(function(){}); done(); });
.end(function (err, getRes3) { if (err) return done(err); var result = _.findWhere(getRes3.body.results, { "_id": id }); redis.createClient.restore(); should.not.exist(result); app.stop(function(){}); done(); });
.end(function (err, getRes3) { if (err) return done(err); redis.createClient.restore(); // console.log(getRes2.body) // console.log(getRes3.body) var result = _.findWhere(getRes3.body.results, { "_id": id }); result.field1.should.eql('foo bar baz!'); app.stop(function(){}); done(); });
it('should fallback to directory cache if Redis client fails', function(done) { delete require.cache[__dirname + '/../../config.js']; config.loadFile(config.configPath()); var EventEmitter = require('events'); var util = require('util'); /* Fake redis client */ function Client() { this.end = function(reallyEnd) { } EventEmitter.call(this); } util.inherits(Client, EventEmitter); var redisClient = new Client(); /* End Fake redis client */ sinon.stub(redis, 'createClient').returns(redisClient); delete require.cache[__dirname + '/../../dadi/lib/']; cache.reset(); var c = cache(app); redis.createClient.restore(); setTimeout(function() { // emit an error event redisClient.emit('error', { code: 'CONNECTION_BROKEN'}); config.get('caching.directory.enabled').should.eql(true) try { app.stop(function(){}); } catch (err) { } done(); }, 1000) });
it('should initialise Redis client', function(done) { delete require.cache[__dirname + '/../../config.js']; config.loadFile(config.configPath()); sinon.stub(redis, 'createClient', fakeredis.createClient); delete require.cache[__dirname + '/../../dadi/lib/']; cache.reset(); try { app.stop(function(){}); //app.start(function(){}); } catch (err) { } var c = cache(app); redis.createClient.restore(); c.redisClient.should.not.be.null; //app.stop(function(){}); done(); });
after(function(done){ redis.createClient.restore(); done(); });
afterEach(function() { redis.createClient.restore(); });
after(() => { redis.createClient.restore() })