1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Remove snack_case and always use camelCase

This commit is contained in:
Ruben Bridgewater
2016-12-18 01:46:58 +01:00
committed by Ruben Bridgewater
parent a86c998a64
commit 28afc33c9a
43 changed files with 1048 additions and 1163 deletions

View File

@@ -58,8 +58,8 @@ describe('client authentication', function () {
assert(now - time < 225, 'Time should be below 255 ms (the reconnect should only take a bit above 100 ms) and is ' + (now - time));
done();
});
var tmp = client.command_queue.get(0).callback;
client.command_queue.get(0).callback = function (err, res) {
var tmp = client.commandQueue.get(0).callback;
client.commandQueue.get(0).callback = function (err, res) {
client.auth = function (pass, callback) {
callback(null, 'retry worked');
};
@@ -115,15 +115,15 @@ describe('client authentication', function () {
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT + '?db=2&password=' + auth);
assert.strictEqual(client.options.db, '2');
assert.strictEqual(client.options.password, auth);
assert.strictEqual(client.auth_pass, auth);
assert.strictEqual(client.authPass, auth);
client.on('ready', function () {
// Set a key so the used database is returned in the info command
client.set('foo', 'bar');
client.get('foo');
assert.strictEqual(client.server_info.db2, undefined);
// Using the info command should update the server_info
assert.strictEqual(client.serverInfo.db2, undefined);
// Using the info command should update the serverInfo
client.info(function (err, res) {
assert(typeof client.server_info.db2 === 'object');
assert(typeof client.serverInfo.db2 === 'object');
});
client.flushdb(done);
});
@@ -134,18 +134,18 @@ describe('client authentication', function () {
if (helper.redisProcess().spawnFailed()) this.skip();
var args = config.configureClient(ip, {
auth_pass: auth
authPass: auth
});
client = redis.createClient.apply(null, args);
client.on('ready', done);
});
it('allows auth and no_ready_check to be provided as config option for client', function (done) {
it('allows auth and noReadyCheck to be provided as config option for client', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
var args = config.configureClient(ip, {
password: auth,
no_ready_check: true
noReadyCheck: true
});
client = redis.createClient.apply(null, args);
client.on('ready', done);
@@ -166,9 +166,9 @@ describe('client authentication', function () {
client = redis.createClient.apply(null, args);
client.auth(auth);
client.on('ready', function () {
if (this.times_connected < 3) {
if (this.timesConnected < 3) {
var interval = setInterval(function () {
if (client.commandQueueLength !== 0) {
if (client.commandQueue.length !== 0) {
return;
}
clearInterval(interval);
@@ -176,7 +176,7 @@ describe('client authentication', function () {
client.stream.destroy();
client.set('foo', 'bar');
client.get('foo'); // Errors would bubble
assert.strictEqual(client.offlineQueueLength, 2);
assert.strictEqual(client.offlineQueue.length, 2);
}, 1);
} else {
done();
@@ -218,7 +218,7 @@ describe('client authentication', function () {
if (helper.redisProcess().spawnFailed()) this.skip();
var args = config.configureClient(ip, {
auth_pass: auth
authPass: auth
});
client = redis.createClient.apply(null, args);
client.on('ready', function () {
@@ -226,11 +226,11 @@ describe('client authentication', function () {
});
});
it('does not allow any commands to be processed if not authenticated using no_ready_check true', function (done) {
it('does not allow any commands to be processed if not authenticated using noReadyCheck true', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
var args = config.configureClient(ip, {
no_ready_check: true
noReadyCheck: true
});
client = redis.createClient.apply(null, args);
client.on('ready', function () {
@@ -257,7 +257,7 @@ describe('client authentication', function () {
it('should emit an error if the provided password is faulty', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient({
password: 'wrong_password'
password: 'wrongPassword'
});
client.once('error', function (err) {
assert.strictEqual(err.message, 'ERR invalid password');
@@ -275,7 +275,7 @@ describe('client authentication', function () {
client.set('foo', 'bar');
client.subscribe('somechannel', 'another channel', function (err, res) {
client.once('ready', function () {
assert.strictEqual(client.pub_sub_mode, 1);
assert.strictEqual(client.pubSubMode, 1);
client.get('foo', function (err, res) {
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message));
done();
@@ -284,7 +284,7 @@ describe('client authentication', function () {
});
client.once('ready', function () {
// Coherent behavior with all other offline commands fires commands before emitting but does not wait till they return
assert.strictEqual(client.pub_sub_mode, 2);
assert.strictEqual(client.pubSubMode, 2);
client.ping(function () { // Make sure all commands were properly processed already
client.stream.destroy();
});
@@ -302,7 +302,7 @@ describe('client authentication', function () {
noReadyCheck: true
});
client = redis.createClient.apply(null, args);
assert.strictEqual(client.selected_db, undefined);
assert.strictEqual(client.selectedDb, undefined);
var end = helper.callFuncAfter(done, 8);
client.on('monitor', function () {
end(); // Should be called for each command after monitor
@@ -310,9 +310,9 @@ describe('client authentication', function () {
client.batch()
.auth(auth)
.SELECT(5, function (err, res) {
assert.strictEqual(client.selected_db, 5);
assert.strictEqual(client.selectedDb, 5);
assert.strictEqual(res, 'OK');
assert.notDeepEqual(client.serverInfo.db5, { avg_ttl: 0, expires: 0, keys: 1 });
assert.notDeepEqual(client.serverInfo.db5, { avgTtl: 0, expires: 0, keys: 1 });
})
.monitor()
.set('foo', 'bar', helper.isString('OK'))

View File

@@ -23,7 +23,7 @@ describe("The 'blpop' method", function () {
it('pops value immediately if list contains values', function (done) {
bclient = redis.createClient.apply(null, args);
redis.debug_mode = true;
redis.debugMode = true;
var text = '';
var unhookIntercept = intercept(function (data) {
text += data;
@@ -32,7 +32,7 @@ describe("The 'blpop' method", function () {
client.rpush('blocking list', 'initial value', helper.isNumber(1));
unhookIntercept();
assert(/^Send 127\.0\.0\.1:6379 id [0-9]+: \*3\r\n\$5\r\nrpush\r\n\$13\r\nblocking list\r\n\$13\r\ninitial value\r\n\n$/.test(text));
redis.debug_mode = false;
redis.debugMode = false;
bclient.blpop('blocking list', 0, function (err, value) {
assert.strictEqual(value[0], 'blocking list');
assert.strictEqual(value[1], 'initial value');

View File

@@ -33,8 +33,8 @@ describe("The 'hgetall' method", function () {
});
it('handles fetching keys set using an object', function (done) {
client.batch().HMSET('msg_test', { message: 'hello' }, undefined).exec();
client.hgetall('msg_test', function (err, obj) {
client.batch().HMSET('msgTest', { message: 'hello' }, undefined).exec();
client.hgetall('msgTest', function (err, obj) {
assert.strictEqual(1, Object.keys(obj).length);
assert.strictEqual(obj.message, 'hello');
done(err);
@@ -52,7 +52,7 @@ describe("The 'hgetall' method", function () {
describe('binary client', function () {
var client;
var args = config.configureClient(ip, {
return_buffers: true
returnBuffers: true
});
beforeEach(function (done) {

View File

@@ -52,7 +52,7 @@ describe("The 'incr' method", function () {
});
it('count above the safe integers as strings', function (done) {
args[2].string_numbers = true;
args[2].stringNumbers = true;
client = redis.createClient.apply(null, args);
// Set a value to the maximum safe allowed javascript number (2^53)
client.set(key, MAX_SAFE_INTEGER, helper.isNotError());

View File

@@ -41,24 +41,24 @@ describe("The 'info' method", function () {
client.set('foo', 'bar');
client.info('keyspace');
client.select(2, function () {
assert.strictEqual(Object.keys(client.server_info).length, 2, 'Key length should be three');
assert.strictEqual(typeof client.server_info.db0, 'object', 'db0 keyspace should be an object');
assert.strictEqual(Object.keys(client.serverInfo).length, 2, 'Key length should be three');
assert.strictEqual(typeof client.serverInfo.db0, 'object', 'db0 keyspace should be an object');
});
client.info(['keyspace']);
client.set('foo', 'bar');
client.info('all', function (err, res) {
assert(Object.keys(client.server_info).length > 3, 'Key length should be way above three');
assert.strictEqual(typeof client.server_info.redis_version, 'string');
assert.strictEqual(typeof client.server_info.db2, 'object');
assert(Object.keys(client.serverInfo).length > 3, 'Key length should be way above three');
assert.strictEqual(typeof client.serverInfo.redis_version, 'string');
assert.strictEqual(typeof client.serverInfo.db2, 'object');
done();
});
});
it('check redis v.2.4 support', function (done) {
var end = helper.callFuncAfter(done, 2);
client.internal_send_command = function (command_obj) {
assert.strictEqual(command_obj.args.length, 0);
assert.strictEqual(command_obj.command, 'info');
client.internalSendCommand = function (commandObj) {
assert.strictEqual(commandObj.args.length, 0);
assert.strictEqual(commandObj.command, 'info');
end();
};
client.info();

View File

@@ -31,22 +31,22 @@ describe("The 'keys' method", function () {
});
it('handles a large packet size', function (done) {
var keys_values = [];
var keysValues = [];
for (var i = 0; i < 200; i++) {
var key_value = [
var keyValue = [
'multibulk:' + crypto.randomBytes(256).toString('hex'), // use long strings as keys to ensure generation of large packet
'test val ' + i
];
keys_values.push(key_value);
keysValues.push(keyValue);
}
client.mset(keys_values.reduce(function (a, b) {
client.mset(keysValues.reduce(function (a, b) {
return a.concat(b);
}), helper.isString('OK'));
client.keys('multibulk:*', function (err, results) {
assert.deepEqual(keys_values.map(function (val) {
assert.deepEqual(keysValues.map(function (val) {
return val[0];
}).sort(), results.sort());
return done(err);

View File

@@ -46,10 +46,10 @@ describe("The 'select' method", function () {
it('changes the database and calls the callback', function (done) {
// default value of null means database 0 will be used.
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
var buffering = client.SELECT(1, function (err, res) {
helper.isNotError()(err, res);
assert.strictEqual(client.selected_db, 1, 'db should be 1 after select');
assert.strictEqual(client.selectedDb, 1, 'db should be 1 after select');
done();
});
assert(typeof buffering === 'boolean');
@@ -58,10 +58,10 @@ describe("The 'select' method", function () {
describe('and a callback is specified', function () {
describe('with a valid db index', function () {
it('selects the appropriate database', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(1, function (err) {
assert.equal(err, null);
assert.equal(client.selected_db, 1, 'we should have selected the new valid DB');
assert.equal(client.selectedDb, 1, 'we should have selected the new valid DB');
done();
});
});
@@ -69,7 +69,7 @@ describe("The 'select' method", function () {
describe('with an invalid db index', function () {
it('returns an error', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(9999, function (err) {
assert.equal(err.code, 'ERR');
assert.equal(err.message, 'ERR invalid DB index');
@@ -82,10 +82,10 @@ describe("The 'select' method", function () {
describe('and no callback is specified', function () {
describe('with a valid db index', function () {
it('selects the appropriate database', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(1);
setTimeout(function () {
assert.equal(client.selected_db, 1, 'we should have selected the new valid DB');
assert.equal(client.selectedDb, 1, 'we should have selected the new valid DB');
done();
}, 25);
});
@@ -93,7 +93,7 @@ describe("The 'select' method", function () {
describe('with an invalid db index', function () {
it('emits an error when callback not provided', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.on('error', function (err) {
assert.strictEqual(err.command, 'SELECT');
@@ -108,14 +108,14 @@ describe("The 'select' method", function () {
describe('reconnection occurs', function () {
it('selects the appropriate database after a reconnect', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(3);
client.set('foo', 'bar', function () {
client.stream.destroy();
});
client.once('ready', function () {
assert.strictEqual(client.selected_db, 3);
assert(typeof client.server_info.db3 === 'object');
assert.strictEqual(client.selectedDb, 3);
assert(typeof client.serverInfo.db3 === 'object');
done();
});
});

View File

@@ -39,9 +39,9 @@ describe("The 'srem' method", function () {
});
});
it('allows multiple values to be removed with send_command', function (done) {
client.send_command('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.send_command('srem', ['set0', 'member1', 'member2'], helper.isNumber(2));
it('allows multiple values to be removed with sendCommand', function (done) {
client.sendCommand('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.sendCommand('srem', ['set0', 'member1', 'member2'], helper.isNumber(2));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 1);
assert.ok(~res.indexOf('member0'));

View File

@@ -28,7 +28,7 @@ describe("The 'zscan' method", function () {
for (var i = 0; i < 500; i++) {
hash['key_' + i] = 'value_' + i;
set.push('member_' + i);
zset.push(i, 'z_member_' + i);
zset.push(i, 'zMember_' + i);
}
client.hmset('hash:1', hash);
client.sadd('set:1', set);

View File

@@ -45,7 +45,7 @@ describe('master slave sync', function () {
var firstInfo;
slave = redis.createClient({
port: port,
retry_strategy: function (options) {
retryStrategy: function (options) {
// Try to reconnect in very small intervals to catch the master_link_status down before the sync completes
return 10;
}
@@ -57,7 +57,7 @@ describe('master slave sync', function () {
i++;
tmp(err, res);
if (!firstInfo || Object.keys(firstInfo).length === 0) {
firstInfo = slave.server_info;
firstInfo = slave.serverInfo;
}
};
@@ -68,7 +68,7 @@ describe('master slave sync', function () {
var end = helper.callFuncAfter(done, 2);
slave.on('ready', function () {
assert.strictEqual(this.server_info.master_link_status, 'up');
assert.strictEqual(this.serverInfo.master_link_status, 'up');
assert.strictEqual(firstInfo.master_link_status, 'down');
assert(i > 1);
this.get('foo300', function (err, res) {

View File

@@ -29,7 +29,7 @@ describe('connection tests', function () {
assert.strictEqual(client.stream.listeners('error').length, 1);
assert.strictEqual(client.address, '"Private stream"');
// Pretent a reconnect event
client.create_stream();
client.createStream();
assert.strictEqual(client.stream, socket);
assert.strictEqual(client.stream.listeners('error').length, 1);
});
@@ -40,7 +40,7 @@ describe('connection tests', function () {
var called = 0;
client = redis.createClient({
port: 9999,
retry_strategy: function (options) {
retryStrategy: function (options) {
var bool = client.quit(function (err, res) {
assert.strictEqual(res, 'OK');
assert.strictEqual(err, null);
@@ -77,7 +77,7 @@ describe('connection tests', function () {
it('calling quit while the connection is down without offline queue should end the connection right away', function (done) {
var called = false;
client = redis.createClient(9999, {
enable_offline_queue: false
enableOfflineQueue: false
});
client.set('foo', 'bar', function (err, res) {
assert.strictEqual(err.message, 'SET can\'t be processed. The connection is not yet established and the offline queue is deactivated.');
@@ -96,7 +96,7 @@ describe('connection tests', function () {
it('calling quit while connected without offline queue should end the connection when all commands have finished', function (done) {
var called = false;
client = redis.createClient({
enable_offline_queue: false
enableOfflineQueue: false
});
client.on('ready', function () {
client.set('foo', 'bar', function (err, res) {
@@ -154,9 +154,9 @@ describe('connection tests', function () {
describe('on lost connection', function () {
it('end connection while retry is still ongoing', function (done) {
var connect_timeout = 1000; // in ms
var connectTimeout = 1000; // in ms
client = redis.createClient({
connect_timeout: connect_timeout
connectTimeout: connectTimeout
});
client.once('ready', function () {
@@ -165,7 +165,7 @@ describe('connection tests', function () {
client.on('reconnecting', function (params) {
client.end(true);
assert.strictEqual(params.times_connected, 1);
assert.strictEqual(params.timesConnected, 1);
setTimeout(done, 5);
});
});
@@ -178,7 +178,7 @@ describe('connection tests', function () {
retryStrategy: function () {}
};
client = redis.createClient(options);
assert.strictEqual(client.connection_options.family, ip === 'IPv6' ? 6 : 4);
assert.strictEqual(client.connectionOptions.family, ip === 'IPv6' ? 6 : 4);
assert.strictEqual(Object.keys(options).length, 4);
var end = helper.callFuncAfter(done, 2);
@@ -220,10 +220,10 @@ describe('connection tests', function () {
});
});
it('retry_strategy used to reconnect', function (done) {
it('retryStrategy used to reconnect', function (done) {
client = redis.createClient({
retry_strategy: function (options) {
if (options.total_retry_time > 150) {
retryStrategy: function (options) {
if (options.totalRetryTime > 150) {
client.set('foo', 'bar', function (err, res) {
assert.strictEqual(err.message, 'Stream connection ended and command aborted.');
assert.strictEqual(err.code, 'NR_CLOSED');
@@ -265,18 +265,18 @@ describe('connection tests', function () {
describe('when not connected', function () {
it.skip('emit an error after the socket timeout exceeded the connect_timeout time', function (done) {
var connect_timeout = 500; // in ms
it.skip('emit an error after the socket timeout exceeded the connectTimeout time', function (done) {
var connectTimeout = 500; // in ms
client = redis.createClient({
// Auto detect ipv4 and use non routable ip to trigger the timeout
host: '10.255.255.1',
connect_timeout: connect_timeout
connectTimeout: connectTimeout
});
process.nextTick(function () {
assert.strictEqual(client.stream.listeners('timeout').length, 1);
});
assert.strictEqual(client.address, '10.255.255.1:6379');
assert.strictEqual(client.connection_options.family, 4);
assert.strictEqual(client.connectionOptions.family, 4);
client.on('reconnecting', function (params) {
throw new Error('No reconnect, since no connection was ever established');
@@ -291,19 +291,19 @@ describe('connection tests', function () {
// The code execution on windows is very slow at times
var add = process.platform !== 'win32' ? 15 : 200;
var now = Date.now();
assert(now - time < connect_timeout + add, 'The real timeout time should be below ' + (connect_timeout + add) + 'ms but is: ' + (now - time));
assert(now - time < connectTimeout + add, 'The real timeout time should be below ' + (connectTimeout + add) + 'ms but is: ' + (now - time));
// Timers sometimes trigger early (e.g. 1ms to early)
assert(now - time >= connect_timeout - 5, 'The real timeout time should be above ' + connect_timeout + 'ms, but it is: ' + (now - time));
assert(now - time >= connectTimeout - 5, 'The real timeout time should be above ' + connectTimeout + 'ms, but it is: ' + (now - time));
done();
});
});
it('use the system socket timeout if the connect_timeout has not been provided', function (done) {
it('use the system socket timeout if the connectTimeout has not been provided', function (done) {
client = redis.createClient({
host: '2001:db8::ff00:42:8329' // auto detect ip v6
});
assert.strictEqual(client.address, '2001:db8::ff00:42:8329:6379');
assert.strictEqual(client.connection_options.family, 6);
assert.strictEqual(client.connectionOptions.family, 6);
process.nextTick(function () {
assert.strictEqual(client.stream.listeners('timeout').length, 0);
done();
@@ -312,7 +312,7 @@ describe('connection tests', function () {
it('clears the socket timeout after a connection has been established', function (done) {
client = redis.createClient({
connect_timeout: 1000
connectTimeout: 1000
});
process.nextTick(function () {
assert.strictEqual(client.stream._idleTimeout, 1000);
@@ -328,7 +328,7 @@ describe('connection tests', function () {
client = redis.createClient({
host: 'localhost',
port: '6379',
connect_timeout: 1000
connectTimeout: 1000
});
client.once('ready', done);
@@ -340,7 +340,7 @@ describe('connection tests', function () {
}
client = redis.createClient({
path: '/tmp/redis.sock',
connect_timeout: 1000
connectTimeout: 1000
});
var end = helper.callFuncAfter(done, 2);
@@ -371,7 +371,7 @@ describe('connection tests', function () {
it('connects with a port only', function (done) {
client = redis.createClient(6379);
assert.strictEqual(client.connection_options.family, 4);
assert.strictEqual(client.connectionOptions.family, 4);
client.on('error', done);
client.once('ready', function () {
@@ -406,7 +406,7 @@ describe('connection tests', function () {
it('connects correctly to localhost and no ready check', function (done) {
client = redis.createClient(undefined, undefined, {
no_ready_check: true
noReadyCheck: true
});
client.on('error', done);
@@ -421,7 +421,7 @@ describe('connection tests', function () {
it('connects correctly to the provided host with the port set to undefined', function (done) {
client = redis.createClient(undefined, 'localhost', {
no_ready_check: true
noReadyCheck: true
});
client.on('error', done);
assert.strictEqual(client.address, 'localhost:6379');
@@ -442,16 +442,16 @@ describe('connection tests', function () {
cb(new Error("ERR unknown command 'info'"));
};
client.once('ready', function () {
assert.strictEqual(Object.keys(client.server_info).length, 0);
assert.strictEqual(Object.keys(client.serverInfo).length, 0);
done();
});
});
it('fake the stream to mock redis', function () {
// This is needed for libraries that want to mock the stream like fakeredis
var temp = redis.RedisClient.prototype.create_stream;
var create_stream_string = String(temp);
redis.RedisClient.prototype.create_stream = function () {
var temp = redis.RedisClient.prototype.createStream;
var createStreamString = String(temp);
redis.RedisClient.prototype.createStream = function () {
this.connected = true;
this.ready = true;
};
@@ -460,15 +460,15 @@ describe('connection tests', function () {
assert.strictEqual(client.ready, true);
assert.strictEqual(client.connected, true);
client.end = function () {};
assert(create_stream_string !== String(redis.RedisClient.prototype.create_stream));
redis.RedisClient.prototype.create_stream = temp;
assert(create_stream_string === String(redis.RedisClient.prototype.create_stream));
assert(createStreamString !== String(redis.RedisClient.prototype.createStream));
redis.RedisClient.prototype.createStream = temp;
assert(createStreamString === String(redis.RedisClient.prototype.createStream));
});
if (ip === 'IPv4') {
it('allows connecting with the redis url to the default host and port, select db 3 and warn about duplicate db option', function (done) {
client = redis.createClient('redis:///3?db=3');
assert.strictEqual(client.selected_db, '3');
assert.strictEqual(client.selectedDb, '3');
client.on('ready', done);
});
@@ -484,9 +484,9 @@ describe('connection tests', function () {
it('allows connecting with the redis url as first parameter and the options as second parameter', function (done) {
client = redis.createClient('//127.0.0.1', {
connect_timeout: 1000
connectTimeout: 1000
});
assert.strictEqual(client.options.connect_timeout, 1000);
assert.strictEqual(client.options.connectTimeout, 1000);
client.on('ready', done);
});
@@ -494,8 +494,8 @@ describe('connection tests', function () {
client = redis.createClient({
url: 'http://foo:porkchopsandwiches@' + config.HOST[ip] + '/3'
});
assert.strictEqual(client.auth_pass, 'porkchopsandwiches');
assert.strictEqual(+client.selected_db, 3);
assert.strictEqual(client.authPass, 'porkchopsandwiches');
assert.strictEqual(+client.selectedDb, 3);
assert(!client.options.port);
assert.strictEqual(client.options.host, config.HOST[ip]);
client.on('ready', done);
@@ -503,7 +503,7 @@ describe('connection tests', function () {
it('allows connecting with the redis url and no auth and options as second parameter', function (done) {
var options = {
detect_buffers: false
detectBuffers: false
};
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, options);
assert.strictEqual(Object.keys(options).length, 1);
@@ -512,7 +512,7 @@ describe('connection tests', function () {
it('allows connecting with the redis url and no auth and options as third parameter', function (done) {
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, null, {
detect_buffers: false
detectBuffers: false
});
client.on('ready', done);
});
@@ -529,8 +529,8 @@ describe('connection tests', function () {
tmp(function (err, res) {
if (!delayed) {
assert(!err);
client.server_info.loading = 1;
client.server_info.loading_eta_seconds = 0.5;
client.serverInfo.loading = 1;
client.serverInfo.loading_eta_seconds = 0.5;
delayed = true;
time = Date.now();
}
@@ -560,8 +560,8 @@ describe('connection tests', function () {
if (!delayed) {
assert(!err);
// Try reconnecting after one second even if redis tells us the time needed is above one second
client.server_info.loading = 1;
client.server_info.loading_eta_seconds = 2.5;
client.serverInfo.loading = 1;
client.serverInfo.loading_eta_seconds = 2.5;
delayed = true;
time = Date.now();
}

View File

@@ -5,11 +5,11 @@ var config = require('./lib/config');
var helper = require('./helper');
var redis = config.redis;
describe('detect_buffers', function () {
describe('detectBuffers', function () {
var client;
var args = config.configureClient('localhost', {
detect_buffers: true
detectBuffers: true
});
beforeEach(function (done) {

View File

@@ -49,7 +49,7 @@ describe('stack traces', function () {
// This is always going to return good stack traces
it('should always return good stack traces for rejected offline commands', function (done) {
var client = redis.createClient({
enable_offline_queue: false
enableOfflineQueue: false
});
client.set('foo', function (err, res) {
assert(/good_traces.spec.js/.test(err.stack));

View File

@@ -6,7 +6,7 @@ var config = require('./lib/config');
var RedisProcess = require('./lib/redis-process');
var StunnelProcess = require('./lib/stunnel-process');
var rp;
var stunnel_process;
var stunnelProcess;
function startRedis (conf, done, port) {
RedisProcess.start(function (err, _rp) {
@@ -46,15 +46,15 @@ module.exports = {
},
startRedis: startRedis,
stopStunnel: function (done) {
if (stunnel_process) {
StunnelProcess.stop(stunnel_process, done);
if (stunnelProcess) {
StunnelProcess.stop(stunnelProcess, done);
} else {
done();
}
},
startStunnel: function (done) {
StunnelProcess.start(function (err, _stunnel_process) {
stunnel_process = _stunnel_process;
StunnelProcess.start(function (err, _stunnelProcess) {
stunnelProcess = _stunnelProcess;
return done(err);
}, path.resolve(__dirname, './conf'));
},
@@ -138,18 +138,18 @@ module.exports = {
if (done) done();
};
},
serverVersionAtLeast: function (connection, desired_version) {
serverVersionAtLeast: function (connection, desiredVersion) {
// Wait until a connection has established (otherwise a timeout is going to be triggered at some point)
if (Object.keys(connection.server_info).length === 0) {
if (Object.keys(connection.serverInfo).length === 0) {
throw new Error('Version check not possible as the client is not yet ready or did not expose the version');
}
// Return true if the server version >= desired_version
var version = connection.server_info.versions;
// Return true if the server version >= desiredVersion
var version = connection.serverInfo.versions;
for (var i = 0; i < 3; i++) {
if (version[i] > desired_version[i]) {
if (version[i] > desiredVersion[i]) {
return true;
}
if (version[i] < desired_version[i]) {
if (version[i] < desiredVersion[i]) {
if (this.skip) this.skip();
return false;
}
@@ -166,9 +166,9 @@ module.exports = {
protocols.push('IPv6', '/tmp/redis.sock');
}
var options = [{
detect_buffers: true
detectBuffers: true
}, {
detect_buffers: false
detectBuffers: false
}];
options.forEach(function (options) {
var strOptions = '';
@@ -209,7 +209,7 @@ module.exports = {
},
killConnection: function (client) {
// Change the connection option to a non existing one and destroy the stream
client.connection_options = {
client.connectionOptions = {
port: 65535,
host: '127.0.0.1',
family: 4

View File

@@ -1,4 +1,4 @@
// Spawned by the good_stacks.spec.js tests
// Spawned by the goodStacks.spec.js tests
'use strict';
var assert = require('assert');

View File

@@ -16,15 +16,15 @@ function once (cb) {
};
}
function StunnelProcess (conf_dir) {
function StunnelProcess (confDir) {
EventEmitter.call(this);
// set up an stunnel to redis; edit the conf file to include required absolute paths
var conf_file = path.resolve(conf_dir, 'stunnel.conf');
var conf_text = fs.readFileSync(conf_file + '.template').toString().replace(/__dirname/g, conf_dir);
var confFile = path.resolve(confDir, 'stunnel.conf');
var confText = fs.readFileSync(confFile + '.template').toString().replace(/__dirname,/g, confDir);
fs.writeFileSync(conf_file, conf_text);
var stunnel = this.stunnel = spawn('stunnel', [conf_file]);
fs.writeFileSync(confFile, confText);
var stunnel = this.stunnel = spawn('stunnel', [confFile]);
// handle child process events, and failure to set up tunnel
var self = this;
@@ -68,9 +68,9 @@ StunnelProcess.prototype.stop = function (done) {
};
module.exports = {
start: function (done, conf_dir) {
start: function (done, confDir) {
done = once(done);
var stunnel = new StunnelProcess(conf_dir);
var stunnel = new StunnelProcess(confDir);
stunnel.once('error', done.bind(done));
stunnel.once('started', done.bind(done, null, stunnel));
},

View File

@@ -1,4 +1,4 @@
// spawned by the unref tests in node_redis.spec.js.
// spawned by the unref tests in nodeRedis.spec.js.
// when configured, unref causes the client to exit
// as soon as there are no outstanding commands.
'use strict';

View File

@@ -22,8 +22,8 @@ describe("The 'multi' method", function () {
var end = helper.callFuncAfter(done, 100);
// Some random object created from http://beta.json-generator.com/
var test_obj = {
'_id': '5642c4c33d4667c4a1fefd99', 'index': 0, 'guid': '5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f', 'isActive': true,
var testObj = {
'Id': '5642c4c33d4667c4a1fefd99', 'index': 0, 'guid': '5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f', 'isActive': true,
'balance': '$1,028.63', 'picture': 'http://placehold.it/32x32', 'age': 31, 'eyeColor': 'green', 'name': {'first': 'Shana', 'last': 'Long'},
'company': 'MANGLO', 'email': 'shana.long@manglo.us', 'phone': '+1 (926) 405-3105', 'address': '747 Dank Court, Norfolk, Ohio, 1112',
'about': 'Eu pariatur in nisi occaecat enim qui consequat nostrud cupidatat id. ' +
@@ -38,14 +38,14 @@ describe("The 'multi' method", function () {
return;
}
// To demonstrate a big payload for hash set field values, let's create a big array
var test_arr = [];
var testArr = [];
var i = 0;
for (; i < 80; i++) {
var new_obj = JSON.parse(JSON.stringify(test_obj));
test_arr.push(new_obj);
var newObj = JSON.parse(JSON.stringify(testObj));
testArr.push(newObj);
}
var json = JSON.stringify(test_arr);
var json = JSON.stringify(testArr);
zlib.deflate(new Buffer(json), function (err, buffer) {
if (err) {
done(err);
@@ -165,13 +165,13 @@ describe("The 'multi' method", function () {
});
// Check if Redis still has the error
client.monitor();
client.send_command('multi');
client.send_command('set', ['foo', 'bar']);
client.send_command('get', ['foo']);
client.send_command('exec', function (err, res) {
client.sendCommand('multi');
client.sendCommand('set', ['foo', 'bar']);
client.sendCommand('get', ['foo']);
client.sendCommand('exec', function (err, res) {
// res[0] is going to be the monitor result of set
// res[1] is going to be the result of the set command
assert(utils.monitor_regex.test(res[0]));
assert(utils.monitorRegex.test(res[0]));
assert.strictEqual(res[1], 'OK');
assert.strictEqual(res.length, 2);
client.end(false);
@@ -184,7 +184,7 @@ describe("The 'multi' method", function () {
multi1.set('m1', '123');
multi1.get('m1');
multi1.exec(done);
assert.strictEqual(client.offline_queue.length, 4);
assert.strictEqual(client.offlineQueue.length, 4);
});
it('executes a pipelined multi properly after a reconnect in combination with the offline queue', function (done) {
@@ -328,15 +328,15 @@ describe("The 'multi' method", function () {
multi1.exec(function () {
// Redis 2.6.5+ will abort transactions with errors
// see: http://redis.io/topics/transactions
var multibar_expected = 1;
var multifoo_expected = 1;
var multibarExpected = 1;
var multifooExpected = 1;
// Confirm that the previous command, while containing an error, still worked.
multi2 = client.multi();
multi2.incr('multibar', helper.isNumber(multibar_expected));
multi2.incr('multifoo', helper.isNumber(multifoo_expected));
multi2.incr('multibar', helper.isNumber(multibarExpected));
multi2.incr('multifoo', helper.isNumber(multifooExpected));
multi2.exec(function (err, replies) {
assert.strictEqual(multibar_expected, replies[0]);
assert.strictEqual(multifoo_expected, replies[1]);
assert.strictEqual(multibarExpected, replies[0]);
assert.strictEqual(multifooExpected, replies[1]);
return done();
});
});
@@ -608,20 +608,20 @@ describe("The 'multi' method", function () {
client.get('foo', helper.isString('bar', done));
});
it('should not use a transaction with exec_atomic if no command is used', function () {
it('should not use a transaction with execAtomic if no command is used', function () {
var multi = client.multi();
var test = false;
multi.exec_batch = function () {
multi.execBatch = function () {
test = true;
};
multi.exec_atomic();
multi.execAtomic();
assert(test);
});
it('should not use a transaction with exec_atomic if only one command is used', function () {
it('should not use a transaction with execAtomic if only one command is used', function () {
var multi = client.multi();
var test = false;
multi.exec_batch = function () {
multi.execBatch = function () {
test = true;
};
multi.set('baz', 'binary');
@@ -629,15 +629,15 @@ describe("The 'multi' method", function () {
assert(test);
});
it('should use transaction with exec_atomic and more than one command used', function (done) {
it('should use transaction with execAtomic and more than one command used', function (done) {
var multi = client.multi();
var test = false;
multi.exec_batch = function () {
multi.execBatch = function () {
test = true;
};
multi.set('baz', 'binary');
multi.get('baz');
multi.exec_atomic(done);
multi.execAtomic(done);
assert(!test);
});
@@ -695,23 +695,23 @@ describe("The 'multi' method", function () {
// subscribe => enters subscribe mode and this does not work in combination with exec (the same for psubscribe, unsubscribe...)
//
// Make sure send_command is not called
client.send_command = function () {
// Make sure sendCommand is not called
client.sendCommand = function () {
throw new Error('failed');
};
assert.strictEqual(client.selected_db, undefined);
assert.strictEqual(client.selectedDb, undefined);
var multi = client.multi();
multi.select(5, function (err, res) {
assert.strictEqual(client.selected_db, 5);
assert.strictEqual(client.selectedDb, 5);
assert.strictEqual(res, 'OK');
assert.notDeepEqual(client.server_info.db5, { avg_ttl: 0, expires: 0, keys: 1 });
assert.notDeepEqual(client.serverInfo.db5, { avg_ttl: 0, expires: 0, keys: 1 });
});
// multi.client('reply', 'on', helper.isString('OK')); // Redis v.3.2
multi.set('foo', 'bar', helper.isString('OK'));
multi.info(function (err, res) {
assert.strictEqual(res.indexOf('# Server\r\nredis_version:'), 0);
assert.deepEqual(client.server_info.db5, { avg_ttl: 0, expires: 0, keys: 1 });
assert.deepEqual(client.serverInfo.db5, { avg_ttl: 0, expires: 0, keys: 1 });
});
multi.get('foo', helper.isString('bar'));
multi.exec(function (err, res) {

View File

@@ -10,21 +10,21 @@ var fork = require('child_process').fork;
var redis = config.redis;
var client;
describe('The node_redis client', function () {
describe('The nodeRedis client', function () {
it('individual commands sanity check', function (done) {
// All commands should work the same in multi context or without
// Therefor individual commands always have to be handled in both cases
fs.readFile(path.resolve(__dirname, '../lib/individualCommands.js'), 'utf8', function (err, data) {
var client_prototype = data.match(/(\n| = )RedisClient\.prototype.[a-zA-Z_]+/g);
var multi_prototype = data.match(/(\n| = )Multi\.prototype\.[a-zA-Z_]+/g);
var clientPrototype = data.match(/(\n| = )RedisClient\.prototype.[a-zA-Z_]+/g);
var multiPrototype = data.match(/(\n| = )Multi\.prototype\.[a-zA-Z_]+/g);
// Check that every entry RedisClient entry has a correspondend Multi entry
assert.strictEqual(client_prototype.filter(function (entry) {
return multi_prototype.indexOf(entry.replace('RedisClient', 'Multi')) === -1;
assert.strictEqual(clientPrototype.filter(function (entry) {
return multiPrototype.indexOf(entry.replace('RedisClient', 'Multi')) === -1;
}).length, 4); // multi and batch are included too
assert.strictEqual(client_prototype.length, multi_prototype.length + 4);
assert.strictEqual(clientPrototype.length, multiPrototype.length + 4);
// Check that all entries exist in uppercase and in lowercase variants
assert.strictEqual(data.match(/(\n| = )RedisClient\.prototype.[a-z_]+/g).length * 2, client_prototype.length);
assert.strictEqual(data.match(/(\n| = )RedisClient\.prototype.[a-z_]+/g).length * 2, clientPrototype.length);
done();
});
});
@@ -46,13 +46,13 @@ describe('The node_redis client', function () {
});
client.once('reconnecting', function () {
process.nextTick(function () {
assert.strictEqual(client.reply_parser.buffer, null);
assert.strictEqual(client.replyParser.buffer, null);
done();
});
});
var partialInput = new Buffer('$100\r\nabcdef');
client.reply_parser.execute(partialInput);
assert.strictEqual(client.reply_parser.buffer.inspect(), partialInput.inspect());
client.replyParser.execute(partialInput);
assert.strictEqual(client.replyParser.buffer.inspect(), partialInput.inspect());
client.stream.destroy();
});
@@ -74,10 +74,10 @@ describe('The node_redis client', function () {
describe('duplicate', function () {
it('check if all options got copied properly', function (done) {
client.selected_db = 2;
client.selectedDb = 2;
var client2 = client.duplicate();
assert.strictEqual(client.connectionId + 1, client2.connection_id);
assert.strictEqual(client2.selected_db, 2);
assert.strictEqual(client.connectionId + 1, client2.connectionId);
assert.strictEqual(client2.selectedDb, 2);
assert(client.connected);
assert(!client2.connected);
for (var elem in client.options) {
@@ -99,16 +99,16 @@ describe('The node_redis client', function () {
it('check if all new options replaced the old ones', function (done) {
var client2 = client.duplicate({
no_ready_check: true
noReadyCheck: true
});
assert(client.connected);
assert(!client2.connected);
assert.strictEqual(client.options.no_ready_check, undefined);
assert.strictEqual(client2.options.no_ready_check, true);
assert.strictEqual(client.options.noReadyCheck, undefined);
assert.strictEqual(client2.options.noReadyCheck, true);
assert.notDeepEqual(client.options, client2.options);
for (var elem in client.options) {
if (client.options.hasOwnProperty(elem)) {
if (elem !== 'no_ready_check') {
if (elem !== 'noReadyCheck') {
assert.strictEqual(client2.options[elem], client.options[elem]);
}
}
@@ -173,12 +173,12 @@ describe('The node_redis client', function () {
str += str;
}
var called = false;
var temp = client.write_buffers.bind(client);
assert(client.fire_strings);
client.write_buffers = function (data) {
var temp = client.writeBuffers.bind(client);
assert(client.fireStrings);
client.writeBuffers = function (data) {
called = true;
// To increase write performance for strings the value is converted to a buffer
assert(!client.fire_strings);
assert(!client.fireStrings);
temp(data);
};
client.multi().set('foo', str).get('foo', function (err, res) {
@@ -188,46 +188,46 @@ describe('The node_redis client', function () {
assert.strictEqual(res[1], str);
done();
});
assert(client.fire_strings);
assert(client.fireStrings);
});
});
describe('send_command', function () {
describe('sendCommand', function () {
it('omitting args should be fine', function (done) {
client.server_info = {};
client.send_command('info');
client.send_command('ping', function (err, res) {
client.serverInfo = {};
client.sendCommand('info');
client.sendCommand('ping', function (err, res) {
assert.strictEqual(res, 'PONG');
// Check if the previous info command used the internal individual info command
assert.notDeepEqual(client.server_info, {});
client.server_info = {};
assert.notDeepEqual(client.serverInfo, {});
client.serverInfo = {};
});
client.send_command('info', null, undefined);
client.send_command('ping', null, function (err, res) {
client.sendCommand('info', null, undefined);
client.sendCommand('ping', null, function (err, res) {
assert.strictEqual(res, 'PONG');
// Check if the previous info command used the internal individual info command
assert.notDeepEqual(client.server_info, {});
client.server_info = {};
assert.notDeepEqual(client.serverInfo, {});
client.serverInfo = {};
});
client.send_command('info', undefined, undefined);
client.send_command('ping', function (err, res) {
client.sendCommand('info', undefined, undefined);
client.sendCommand('ping', function (err, res) {
assert.strictEqual(res, 'PONG');
// Check if the previous info command used the internal individual info command
assert.notDeepEqual(client.server_info, {});
client.server_info = {};
assert.notDeepEqual(client.serverInfo, {});
client.serverInfo = {};
});
client.send_command('info', undefined, function (err, res) {
client.sendCommand('info', undefined, function (err, res) {
assert(/redis_version/.test(res));
// The individual info command should also be called by using send_command
// console.log(info, client.server_info);
assert.notDeepEqual(client.server_info, {});
// The individual info command should also be called by using sendCommand
// console.log(info, client.serverInfo);
assert.notDeepEqual(client.serverInfo, {});
done();
});
});
it('using multi with sendCommand should work as individual command instead of using the internal multi', function (done) {
// This is necessary to keep backwards compatibility and it is the only way to handle multis as you want in node_redis
// This is necessary to keep backwards compatibility and it is the only way to handle multis as you want in nodeRedis
client.sendCommand('multi');
client.sendCommand('set', ['foo', 'bar'], helper.isString('QUEUED'));
client.get('foo');
@@ -240,9 +240,9 @@ describe('The node_redis client', function () {
});
it('multi should be handled special', function (done) {
client.send_command('multi', undefined, helper.isString('OK'));
client.sendCommand('multi', undefined, helper.isString('OK'));
var args = ['test', 'bla'];
client.send_command('set', args, helper.isString('QUEUED'));
client.sendCommand('set', args, helper.isString('QUEUED'));
assert.deepEqual(args, ['test', 'bla']); // Check args manipulation
client.get('test', helper.isString('QUEUED'));
client.exec(function (err, res) {
@@ -255,13 +255,13 @@ describe('The node_redis client', function () {
it('using another type as cb should throw', function () {
try {
client.send_command('set', ['test', 'bla'], [true]);
client.sendCommand('set', ['test', 'bla'], [true]);
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "Array" for callback function');
}
try {
client.send_command('set', ['test', 'bla'], null);
client.sendCommand('set', ['test', 'bla'], null);
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "null" for callback function');
@@ -270,19 +270,19 @@ describe('The node_redis client', function () {
it('command argument has to be of type string', function () {
try {
client.send_command(true, ['test', 'bla'], function () {});
client.sendCommand(true, ['test', 'bla'], function () {});
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "Boolean" for command name');
}
try {
client.send_command(undefined, ['test', 'bla'], function () {});
client.sendCommand(undefined, ['test', 'bla'], function () {});
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "undefined" for command name');
}
try {
client.send_command(null, ['test', 'bla'], function () {});
client.sendCommand(null, ['test', 'bla'], function () {});
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "null" for command name');
@@ -291,7 +291,7 @@ describe('The node_redis client', function () {
it('args may only be of type Array or undefined', function () {
try {
client.send_command('info', 123);
client.sendCommand('info', 123);
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "Number" for args');
@@ -300,7 +300,7 @@ describe('The node_redis client', function () {
it('passing a callback as args and as callback should throw', function () {
try {
client.send_command('info', function a () {}, function b () {});
client.sendCommand('info', function a () {}, function b () {});
throw new Error('failed');
} catch (err) {
assert.strictEqual(err.message, 'Wrong input type "Function" for args');
@@ -308,9 +308,9 @@ describe('The node_redis client', function () {
});
it('multi should be handled special', function (done) {
client.send_command('multi', undefined, helper.isString('OK'));
client.sendCommand('multi', undefined, helper.isString('OK'));
var args = ['test', 'bla'];
client.send_command('set', args, helper.isString('QUEUED'));
client.sendCommand('set', args, helper.isString('QUEUED'));
assert.deepEqual(args, ['test', 'bla']); // Check args manipulation
client.get('test', helper.isString('QUEUED'));
client.exec(function (err, res) {
@@ -322,7 +322,7 @@ describe('The node_redis client', function () {
});
it('the args array may contain a arbitrary number of arguments', function (done) {
client.send_command('mset', ['foo', 1, 'bar', 2, 'baz', 3], helper.isString('OK'));
client.sendCommand('mset', ['foo', 1, 'bar', 2, 'baz', 3], helper.isString('OK'));
client.mget(['foo', 'bar', 'baz'], function (err, res) {
// As the multi command is handled individually by the user he also has to handle the return value
assert.strictEqual(res[0].toString(), '1');
@@ -332,8 +332,8 @@ describe('The node_redis client', function () {
});
});
it('send_command with callback as args', function (done) {
client.send_command('abcdef', function (err, res) {
it('sendCommand with callback as args', function (done) {
client.sendCommand('abcdef', function (err, res) {
assert.strictEqual(err.message, "ERR unknown command 'abcdef'");
done();
});
@@ -341,11 +341,11 @@ describe('The node_redis client', function () {
});
describe('retry_unfulfilled_commands', function () {
describe('retryUnfulfilledCommands', function () {
it('should retry all commands instead of returning an error if a command did not yet return after a connection loss', function (done) {
var bclient = redis.createClient({
retry_unfulfilled_commands: true
retryUnfulfilledCommands: true
});
bclient.blpop('blocking list 2', 5, function (err, value) {
assert.strictEqual(value[0], 'blocking list 2');
@@ -426,8 +426,8 @@ describe('The node_redis client', function () {
}
});
it('emits an aggregate error if no callback was present for multiple commands in debug_mode', function (done) {
redis.debug_mode = true;
it('emits an aggregate error if no callback was present for multiple commands in debugMode', function (done) {
redis.debugMode = true;
var unhookIntercept = intercept(function (data) {
return ''; // Don't print the debug messages
});
@@ -449,11 +449,11 @@ describe('The node_redis client', function () {
});
client.end(true);
unhookIntercept();
redis.debug_mode = false;
redis.debugMode = false;
});
it('emits an abort error if no callback was present for a single commands', function (done) {
redis.debug_mode = true;
redis.debugMode = true;
var unhookIntercept = intercept(function (data) {
return ''; // Don't print the debug messages
});
@@ -470,10 +470,10 @@ describe('The node_redis client', function () {
});
client.end(true);
unhookIntercept();
redis.debug_mode = false;
redis.debugMode = false;
});
it('does not emit abort errors if no callback was present while not being in debug_mode ', function (done) {
it('does not emit abort errors if no callback was present while not being in debugMode ', function (done) {
client.set('foo', 'bar');
client.end(true);
setTimeout(done, 100);
@@ -492,7 +492,7 @@ describe('The node_redis client', function () {
client.quit(function () {
client.get('foo', function (err, res) {
assert.strictEqual(err.message, 'Stream connection ended and command aborted. It might have been processed.');
assert.strictEqual(client.offline_queue.length, 0);
assert.strictEqual(client.offlineQueue.length, 0);
done();
});
});
@@ -506,7 +506,7 @@ describe('The node_redis client', function () {
client.get('foo', function (err, res) {
assert.strictEqual(err.message, 'GET can\'t be processed. The connection is already closed.');
assert.strictEqual(err.command, 'GET');
assert.strictEqual(client.offline_queue.length, 0);
assert.strictEqual(client.offlineQueue.length, 0);
done();
});
}, 50);
@@ -518,7 +518,7 @@ describe('The node_redis client', function () {
client.on('error', function (err) {
assert.strictEqual(err.message, 'SET can\'t be processed. The connection is already closed.');
assert.strictEqual(err.command, 'SET');
assert.strictEqual(client.offline_queue_length, 0);
assert.strictEqual(client.offlineQueue.length, 0);
done();
});
setTimeout(function () {
@@ -530,13 +530,13 @@ describe('The node_redis client', function () {
describe('when redis closes unexpectedly', function () {
it('reconnects and can retrieve the pre-existing data', function (done) {
client.on('reconnecting', function on_recon (params) {
client.on('connect', function on_connect () {
client.on('reconnecting', function onRecon (params) {
client.on('connect', function onConnect () {
var end = helper.callFuncAfter(function () {
client.removeListener('connect', on_connect);
client.removeListener('reconnecting', on_recon);
assert.strictEqual(client.server_info.db0.keys, 2);
assert.strictEqual(Object.keys(client.server_info.db0).length, 3);
client.removeListener('connect', onConnect);
client.removeListener('reconnecting', onRecon);
assert.strictEqual(client.serverInfo.db0.keys, 2);
assert.strictEqual(Object.keys(client.serverInfo.db0).length, 3);
done();
}, 4);
client.get('recon 1', helper.isString('one', end));
@@ -555,11 +555,11 @@ describe('The node_redis client', function () {
});
it('reconnects properly when monitoring', function (done) {
client.on('reconnecting', function on_recon (params) {
client.on('ready', function on_ready () {
client.on('reconnecting', function onRecon (params) {
client.on('ready', function onReady () {
assert.strictEqual(client.monitoring, true, 'monitoring after reconnect');
client.removeListener('ready', on_ready);
client.removeListener('reconnecting', on_recon);
client.removeListener('ready', onReady);
client.removeListener('reconnecting', onRecon);
done();
});
});
@@ -579,7 +579,7 @@ describe('The node_redis client', function () {
describe("and it's subscribed to a channel", function () {
// "Connection in subscriber mode, only subscriber commands may be used"
it('reconnects, unsubscribes, and can retrieve the pre-existing data', function (done) {
client.on('ready', function on_connect () {
client.on('ready', function onConnect () {
client.unsubscribe(helper.isNotError());
client.on('unsubscribe', function (channel, count) {
@@ -599,7 +599,7 @@ describe('The node_redis client', function () {
});
it('reconnects, unsubscribes, and can retrieve the pre-existing data of a explicit channel', function (done) {
client.on('ready', function on_connect () {
client.on('ready', function onConnect () {
client.unsubscribe('recon channel', helper.isNotError());
client.on('unsubscribe', function (channel, count) {
@@ -709,7 +709,7 @@ describe('The node_redis client', function () {
monitorClient.on('monitor', function (time, args, rawOutput) {
assert.strictEqual(monitorClient.monitoring, true);
responses.push(args);
assert(utils.monitor_regex.test(rawOutput), rawOutput);
assert(utils.monitorRegex.test(rawOutput), rawOutput);
if (responses.length === 6) {
assert.deepEqual(responses[0], ['mget', 'some', 'keys', 'foo', 'bar']);
assert.deepEqual(responses[1], ['set', 'json', '{"foo":"123","bar":"sdflkdfsjk","another":false}']);
@@ -722,9 +722,9 @@ describe('The node_redis client', function () {
});
});
it('monitors returns strings in the rawOutput even with return_buffers activated', function (done) {
it('monitors returns strings in the rawOutput even with returnBuffers activated', function (done) {
var monitorClient = redis.createClient({
return_buffers: true
returnBuffers: true
});
monitorClient.MONITOR(function (err, res) {
@@ -735,7 +735,7 @@ describe('The node_redis client', function () {
monitorClient.on('monitor', function (time, args, rawOutput) {
assert.strictEqual(typeof rawOutput, 'string');
assert(utils.monitor_regex.test(rawOutput), rawOutput);
assert(utils.monitorRegex.test(rawOutput), rawOutput);
assert.deepEqual(args, ['mget', 'hello', 'world']);
// Quit immediatly ends monitoring mode and therefore does not stream back the quit command
monitorClient.quit(done);
@@ -748,7 +748,7 @@ describe('The node_redis client', function () {
client.mget('hello', 'world');
client.on('monitor', function (time, args, rawOutput) {
assert.strictEqual(client.monitoring, true);
assert(utils.monitor_regex.test(rawOutput), rawOutput);
assert(utils.monitorRegex.test(rawOutput), rawOutput);
assert.deepEqual(args, ['mget', 'hello', 'world']);
if (i++ === 2) {
// End after two reconnects
@@ -769,7 +769,7 @@ describe('The node_redis client', function () {
});
client.on('monitor', function (time, args, rawOutput) {
assert.strictEqual(client.monitoring, true);
assert(utils.monitor_regex.test(rawOutput), rawOutput);
assert(utils.monitorRegex.test(rawOutput), rawOutput);
assert.deepEqual(args, ['mget', 'hello', 'world']);
if (i++ === 2) {
// End after two reconnects
@@ -822,7 +822,7 @@ describe('The node_redis client', function () {
var called = false;
client.on('monitor', function (time, args, rawOutput) {
responses.push(args);
assert(utils.monitor_regex.test(rawOutput), rawOutput);
assert(utils.monitorRegex.test(rawOutput), rawOutput);
if (responses.length === 7) {
assert.deepEqual(responses[0], ['subscribe', '/foo', '/bar']);
assert.deepEqual(responses[1], ['unsubscribe', '/bar']);
@@ -851,10 +851,10 @@ describe('The node_redis client', function () {
describe('utf8', function () {
it('handles utf-8 keys', function (done) {
var utf8_sample = 'ಠ_ಠ';
client.set(['utf8test', utf8_sample], helper.isString('OK'));
var utf8Sample = 'ಠ_ಠ';
client.set(['utf8test', utf8Sample], helper.isString('OK'));
client.get(['utf8test'], function (err, obj) {
assert.strictEqual(utf8_sample, obj);
assert.strictEqual(utf8Sample, obj);
done(err);
});
});
@@ -904,14 +904,14 @@ describe('The node_redis client', function () {
// assert(fired);
// done();
// });
// assert.strictEqual(client.offline_queue.length, 1);
// assert.strictEqual(client.command_queue.length, 1);
// assert.strictEqual(client.offlineQueue.length, 1);
// assert.strictEqual(client.commandQueue.length, 1);
// client.on('connect', function () {
// assert.strictEqual(client.offline_queue.length, 1);
// assert.strictEqual(client.command_queue.length, 1);
// assert.strictEqual(client.offlineQueue.length, 1);
// assert.strictEqual(client.commandQueue.length, 1);
// });
// client.on('ready', function () {
// assert.strictEqual(client.offline_queue.length, 0);
// assert.strictEqual(client.offlineQueue.length, 0);
// });
// });
});
@@ -942,13 +942,13 @@ describe('The node_redis client', function () {
// ready is called in a reply
process.nextTick(function () {
// Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set
client.reply_parser.execute(new Buffer('a*1\r*1\r$1`zasd\r\na'));
client.replyParser.execute(new Buffer('a*1\r*1\r$1`zasd\r\na'));
});
});
});
});
describe('enable_offline_queue', function () {
describe('enableOfflineQueue', function () {
describe('true', function () {
it('does not return an error and enqueues operation', function (done) {
client = redis.createClient(9999);
@@ -964,7 +964,7 @@ describe('The node_redis client', function () {
});
setTimeout(function () {
assert.strictEqual(client.offline_queue.length, 1);
assert.strictEqual(client.offlineQueue.length, 1);
finished = true;
done();
}, 25);
@@ -974,6 +974,7 @@ describe('The node_redis client', function () {
it.skip('enqueues operation and keep the queue while trying to reconnect', function (done) {
client = redis.createClient(9999, null, {
retryStrategy: function (options) {
console.log(options)
if (options.attempt < 4) {
return 200;
}
@@ -984,7 +985,7 @@ describe('The node_redis client', function () {
client.on('error', function (err) {
if (err.code === 'CONNECTION_BROKEN') {
assert(i, 3);
assert.strictEqual(client.offline_queue.length, 0);
assert.strictEqual(client.offlineQueue.length, 0);
assert.strictEqual(err.origin.code, 'ECONNREFUSED');
if (!(err instanceof redis.AbortError)) {
done();
@@ -1001,10 +1002,10 @@ describe('The node_redis client', function () {
client.on('reconnecting', function (params) {
i++;
assert.equal(params.attempt, i);
assert.strictEqual(params.times_connected, 0);
assert.strictEqual(params.timesConnected, 0);
assert(params.error instanceof Error);
assert(typeof params.total_retry_time === 'number');
assert.strictEqual(client.offline_queue.length, 2);
assert(typeof params.totalRetryTime === 'number');
assert.strictEqual(client.offlineQueue.length, 2);
});
// Should work with either a callback or without
@@ -1012,7 +1013,7 @@ describe('The node_redis client', function () {
client.set('foo', 'bar', function (err, result) {
assert(i, 3);
assert(err);
assert.strictEqual(client.offline_queue.length, 0);
assert.strictEqual(client.offlineQueue.length, 0);
});
});
@@ -1031,20 +1032,20 @@ describe('The node_redis client', function () {
multi.set('foo' + (i + 2), 'bar' + (i + 2));
}
multi.exec();
assert.equal(client.command_queue_length, 15);
assert.equal(client.commandQueue.length, 15);
helper.killConnection(client);
});
var end = helper.callFuncAfter(done, 3);
client.on('error', function (err) {
if (err.command === 'EXEC') {
assert.strictEqual(client.command_queue.length, 0);
assert.strictEqual(client.commandQueue.length, 0);
assert.strictEqual(err.errors.length, 9);
assert.strictEqual(err.errors[1].command, 'SET');
assert.deepEqual(err.errors[1].args, ['foo1', 'bar1']);
end();
} else if (err.code === 'UNCERTAIN_STATE') {
assert.strictEqual(client.command_queue.length, 0);
assert.strictEqual(client.commandQueue.length, 0);
assert.strictEqual(err.errors.length, 4);
assert.strictEqual(err.errors[0].command, 'SET');
assert.deepEqual(err.errors[0].args, ['foo0', 'bar0']);
@@ -1063,7 +1064,7 @@ describe('The node_redis client', function () {
it('stream not writable', function (done) {
client = redis.createClient({
enable_offline_queue: false
enableOfflineQueue: false
});
client.on('ready', function () {
client.stream.destroy();
@@ -1076,13 +1077,13 @@ describe('The node_redis client', function () {
it('emit an error and does not enqueues operation', function (done) {
client = redis.createClient(9999, null, {
enable_offline_queue: false
enableOfflineQueue: false
});
var end = helper.callFuncAfter(done, 3);
client.on('error', function (err) {
assert(/offline queue is deactivated|ECONNREFUSED/.test(err.message));
assert.equal(client.command_queue.length, 0);
assert.equal(client.commandQueue.length, 0);
end();
});
@@ -1099,10 +1100,10 @@ describe('The node_redis client', function () {
it('flushes the command queue if connection is lost', function (done) {
client = redis.createClient({
enable_offline_queue: false
enableOfflineQueue: false
});
redis.debug_mode = true;
redis.debugMode = true;
var unhookIntercept = intercept(function () {
return '';
});
@@ -1118,13 +1119,13 @@ describe('The node_redis client', function () {
multi.set('foo' + (i + 2), 'bar' + (i + 2));
}
multi.exec();
assert.equal(client.command_queue.length, 15);
assert.equal(client.commandQueue.length, 15);
helper.killConnection(client);
});
var end = helper.callFuncAfter(done, 3);
client.on('error', function (err) {
assert.equal(client.command_queue.length, 0);
assert.equal(client.commandQueue.length, 0);
if (err.command === 'EXEC') {
assert.equal(err.errors.length, 9);
end();
@@ -1135,7 +1136,7 @@ describe('The node_redis client', function () {
assert.equal(err.code, 'ECONNREFUSED');
assert.equal(err.errno, 'ECONNREFUSED');
assert.equal(err.syscall, 'connect');
redis.debug_mode = false;
redis.debugMode = false;
client.end(true);
unhookIntercept();
end();

View File

@@ -35,7 +35,7 @@ describe('publish/subscribe', function () {
beforeEach(function (done) {
sub.end(false);
sub = redis.createClient({
disable_resubscribing: true
disableResubscribing: true
});
sub.once('connect', function () {
done();
@@ -57,7 +57,7 @@ describe('publish/subscribe', function () {
sub.on('reconnecting', function () {
a = true;
sub.on('ready', function () {
assert.strictEqual(sub.command_queue.length, 0);
assert.strictEqual(sub.commandQueue.length, 0);
done();
});
});
@@ -66,11 +66,11 @@ describe('publish/subscribe', function () {
});
});
describe('string_numbers and pub sub', function () {
describe('stringNumbers and pub sub', function () {
beforeEach(function (done) {
sub.end(false);
sub = redis.createClient({
string_numbers: true
stringNumbers: true
});
sub.once('connect', function () {
done();
@@ -90,8 +90,8 @@ describe('publish/subscribe', function () {
});
sub.subscribe(channel, channel2);
sub.unsubscribe(function (err, res) { // Do not pass a channel here!
assert.strictEqual(sub.pub_sub_mode, 2);
assert.deepEqual(sub.subscription_set, {});
assert.strictEqual(sub.pubSubMode, 2);
assert.deepEqual(sub.subscriptionSet, {});
end();
});
sub.set('foo', 'bar', helper.isString('OK'));
@@ -121,7 +121,7 @@ describe('publish/subscribe', function () {
var a = false;
sub.end(true);
sub = redis.createClient({
detect_buffers: true
detectBuffers: true
});
sub.on('subscribe', function (chnl, count) {
if (chnl.inspect() === new Buffer([0xAA, 0xBB, 0x00, 0xF0]).inspect()) {
@@ -178,7 +178,7 @@ describe('publish/subscribe', function () {
sub.subscribe(channel);
});
it('handles SUB_UNSUB_MSG_SUB', function (done) {
it('handles SUB UNSUB MSG SUB', function (done) {
sub.subscribe('chan8');
sub.subscribe('chan9');
sub.unsubscribe('chan9');
@@ -186,7 +186,7 @@ describe('publish/subscribe', function () {
sub.subscribe('chan9', done);
});
it('handles SUB_UNSUB_MSG_SUB 2', function (done) {
it('handles SUB UNSUB MSG SUB 2', function (done) {
sub.psubscribe('abc*', helper.isString('abc*'));
sub.subscribe('xyz');
sub.unsubscribe('xyz');
@@ -263,7 +263,7 @@ describe('publish/subscribe', function () {
it('handles multiple channels with the same channel name properly, even with buffers', function (done) {
var channels = ['a', 'b', 'a', new Buffer('a'), 'c', 'b'];
var subscribed_channels = [1, 2, 2, 2, 3, 3];
var subscribedChannels = [1, 2, 2, 2, 3, 3];
var i = 0;
sub.subscribe(channels);
sub.on('subscribe', function (channel, count) {
@@ -272,7 +272,7 @@ describe('publish/subscribe', function () {
} else {
assert.strictEqual(channel, channels[i].toString());
}
assert.strictEqual(count, subscribed_channels[i]);
assert.strictEqual(count, subscribedChannels[i]);
i++;
});
sub.unsubscribe('a', 'c', 'b');
@@ -486,24 +486,25 @@ describe('publish/subscribe', function () {
describe('psubscribe', function () {
it('allows all channels to be subscribed to using a * pattern', function (done) {
sub.subscribe('/foo');
var sub2 = redis.createClient({
return_buffers: true
returnBuffers: true
});
sub2.on('ready', function () {
sub2.batch().psubscribe('*', helper.isString('*')).exec();
sub2.subscribe('/foo');
sub2.on('pmessage', function (pattern, channel, message) {
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
assert.strictEqual(message.inspect(), new Buffer('hello world').inspect());
sub2.quit(done);
sub.subscribe('/foo', function () {
sub2.on('ready', function () {
sub2.batch().psubscribe('*', helper.isString('*')).exec();
sub2.subscribe('/foo');
sub2.on('pmessage', function (pattern, channel, message) {
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
assert.strictEqual(message.inspect(), new Buffer('hello world').inspect());
sub2.quit(done);
});
pub.pubsub('numsub', '/foo', function (err, res) {
assert.deepEqual(res, ['/foo', 2]);
});
// sub2 is counted twice as it subscribed with psubscribe and subscribe
pub.publish('/foo', 'hello world', helper.isNumber(3));
});
pub.pubsub('numsub', '/foo', function (err, res) {
assert.deepEqual(res, ['/foo', 2]);
});
// sub2 is counted twice as it subscribed with psubscribe and subscribe
pub.publish('/foo', 'hello world', helper.isNumber(3));
});
});
@@ -513,21 +514,14 @@ describe('publish/subscribe', function () {
sub.set('foo', data, function () {
sub.get('foo');
sub.stream.once('data', function () {
assert.strictEqual(sub.message_buffers, false);
assert.strictEqual(sub.messageBuffers, false);
assert.strictEqual(sub.shouldBuffer, false);
sub.on('pmessageBuffer', function (pattern, channel, message) {
if (parser !== 'javascript' && typeof pattern === 'string') {
pattern = new Buffer(pattern);
channel = new Buffer(channel);
}
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
sub.quit(end);
});
if (parser === 'javascript') {
assert.notStrictEqual(sub.message_buffers, sub.buffers);
}
assert.notStrictEqual(sub.messageBuffers, sub.buffers);
});
var batch = sub.batch();
batch.psubscribe('*');
@@ -553,7 +547,7 @@ describe('publish/subscribe', function () {
});
pub.publish('/foo', 'hello world', helper.isNumber(2));
});
// Either message_buffers or buffers has to be true, but not both at the same time
// Either messageBuffers or buffers has to be true, but not both at the same time
sub.on('pmessage', function (pattern, channel, message) {
assert.strictEqual(pattern, '*');
assert.strictEqual(channel, '/foo');

View File

@@ -25,7 +25,7 @@ describe('rename commands', function () {
beforeEach(function (done) {
if (helper.redisProcess().spawnFailed()) return done();
client = redis.createClient({
rename_commands: {
renameCommands: {
set: '807081f5afa96845a02816a28b7258c3',
GETRANGE: '9e3102b15cf231c4e9e940f284744fe0'
}
@@ -120,7 +120,7 @@ describe('rename commands', function () {
client.end(true);
client = redis.createClient({
rename_commands: {
renameCommands: {
set: '807081f5afa96845a02816a28b7258c3'
},
prefix: 'baz'

View File

@@ -5,29 +5,29 @@ var config = require('./lib/config');
var helper = require('./helper');
var redis = config.redis;
describe('return_buffers', function () {
describe('returnBuffers', function () {
helper.allTests(function (ip, basicArgs) {
describe('using ' + ip, function () {
var client;
var args = config.configureClient(ip, {
return_buffers: true,
detect_buffers: true
returnBuffers: true,
detectBuffers: true
});
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
var i = 1;
if (args[2].detect_buffers) {
// Test if detect_buffer option was deactivated
assert.strictEqual(client.options.detect_buffers, false);
args[2].detect_buffers = false;
if (args[2].detectBuffers) {
// Test if detectBuffer option was deactivated
assert.strictEqual(client.options.detectBuffers, false);
args[2].detectBuffers = false;
i++;
}
var end = helper.callFuncAfter(done, i);
client.on('warning', function (msg) {
assert.strictEqual(msg, 'WARNING: You activated return_buffers and detect_buffers at the same time. The return value is always going to be a buffer.');
assert.strictEqual(msg, 'WARNING: You activated returnBuffers and detectBuffers at the same time. The return value is always going to be a buffer.');
end();
});
client.once('error', done);
@@ -244,7 +244,7 @@ describe('return_buffers', function () {
var message = new Buffer('test message');
var args = config.configureClient(ip, {
return_buffers: true
returnBuffers: true
});
beforeEach(function (done) {

View File

@@ -8,20 +8,20 @@ var path = require('path');
var redis = config.redis;
var utils = require('../lib/utils');
var tls_options = {
var tlsOptions = {
servername: 'redis.js.org',
rejectUnauthorized: true,
ca: [ String(fs.readFileSync(path.resolve(__dirname, './conf/redis.js.org.cert'))) ]
};
var tls_port = 6380;
var tlsPort = 6380;
// Use skip instead of returning to indicate what tests really got skipped
var skip = false;
// Wait until stunnel4 is in the travis whitelist
// Check: https://github.com/travis-ci/apt-package-whitelist/issues/403
// If this is merged, remove the travis env checks
describe('TLS connection tests', function () {
describe.skip('TLS connection tests', function () {
before(function (done) {
// Print the warning when the tests run instead of while starting mocha
@@ -53,14 +53,14 @@ describe('TLS connection tests', function () {
describe('on lost connection', function () {
it.skip('emit an error after max retry timeout and do not try to reconnect afterwards', function (done) {
if (skip) this.skip();
var connect_timeout = 500; // in ms
var connectTimeout = 500; // in ms
client = redis.createClient({
connect_timeout: connect_timeout,
port: tls_port,
tls: tls_options
connectTimeout: connectTimeout,
port: tlsPort,
tls: tlsOptions
});
var time = 0;
assert.strictEqual(client.address, '127.0.0.1:' + tls_port);
assert.strictEqual(client.address, '127.0.0.1:' + tlsPort);
client.once('ready', function () {
helper.killConnection(client);
@@ -73,12 +73,12 @@ describe('TLS connection tests', function () {
client.on('error', function (err) {
if (/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message)) {
process.nextTick(function () {
assert.strictEqual(time, connect_timeout);
assert.strictEqual(client.emitted_end, true);
assert.strictEqual(time, connectTimeout);
assert.strictEqual(client.emittedEnd, true);
assert.strictEqual(client.connected, false);
assert.strictEqual(client.ready, false);
assert.strictEqual(client.closing, true);
assert.strictEqual(time, connect_timeout);
assert.strictEqual(time, connectTimeout);
done();
});
}
@@ -90,18 +90,18 @@ describe('TLS connection tests', function () {
it('connect with host and port provided in the tls object', function (done) {
if (skip) this.skip();
var tls = utils.clone(tls_options);
tls.port = tls_port;
var tls = utils.clone(tlsOptions);
tls.port = tlsPort;
tls.host = 'localhost';
client = redis.createClient({
connect_timeout: 1000,
connectTimeout: 1000,
tls: tls
});
// verify connection is using TCP, not UNIX socket
assert.strictEqual(client.connection_options.host, 'localhost');
assert.strictEqual(client.connection_options.port, tls_port);
assert.strictEqual(client.address, 'localhost:' + tls_port);
assert.strictEqual(client.connectionOptions.host, 'localhost');
assert.strictEqual(client.connectionOptions.port, tlsPort);
assert.strictEqual(client.address, 'localhost:' + tlsPort);
assert(client.stream.encrypted);
client.set('foo', 'bar');
@@ -110,15 +110,15 @@ describe('TLS connection tests', function () {
it('fails to connect because the cert is not correct', function (done) {
if (skip) this.skip();
var faulty_cert = utils.clone(tls_options);
faulty_cert.ca = [ String(fs.readFileSync(path.resolve(__dirname, './conf/faulty.cert'))) ];
var faultyCert = utils.clone(tlsOptions);
faultyCert.ca = [ String(fs.readFileSync(path.resolve(__dirname, './conf/faulty.cert'))) ];
client = redis.createClient({
host: 'localhost',
connect_timeout: 1000,
port: tls_port,
tls: faulty_cert
connectTimeout: 1000,
port: tlsPort,
tls: faultyCert
});
assert.strictEqual(client.address, 'localhost:' + tls_port);
assert.strictEqual(client.address, 'localhost:' + tlsPort);
client.on('error', function (err) {
assert(/DEPTH_ZERO_SELF_SIGNED_CERT/.test(err.code || err.message), err);
client.end(true);

View File

@@ -122,9 +122,9 @@ describe('createClient options', function () {
});
unhookIntercept();
assert.strictEqual(text,
'node_redis: WARNING: You passed the db option twice!\n' +
'node_redis: WARNING: You passed the port option twice!\n' +
'node_redis: WARNING: You passed the password option twice!\n'
'nodeRedis: WARNING: You passed the db option twice!\n' +
'nodeRedis: WARNING: You passed the port option twice!\n' +
'nodeRedis: WARNING: You passed the password option twice!\n'
);
assert.strictEqual(Object.keys(options).length, 5);
assert.strictEqual(options.option.length, 3);
@@ -162,7 +162,7 @@ describe('createClient options', function () {
unhookIntercept();
assert.strictEqual(Object.keys(options).length, 1);
assert.strictEqual(options.host, 'abc');
assert.strictEqual(text, 'node_redis: WARNING: You passed "http" as protocol instead of the "redis" protocol!\n');
assert.strictEqual(text, 'nodeRedis: WARNING: You passed "http" as protocol instead of the "redis" protocol!\n');
});
});

View File

@@ -28,25 +28,6 @@ describe('utils.js', function () {
assert.strictEqual(Object.keys(b).length, 0);
});
it('transform camelCase options to snake_case and add the camel_case option', function () {
var a = utils.clone({
optionOneTwo: true,
retryStrategy: false,
nested: {
onlyContainCamelCaseOnce: true
},
tls: {
rejectUnauthorized: true
}
});
assert.strictEqual(Object.keys(a).length, 5);
assert.strictEqual(a.option_one_two, true);
assert.strictEqual(a.retry_strategy, false);
assert.strictEqual(a.camel_case, true);
assert.strictEqual(a.tls.rejectUnauthorized, true);
assert.strictEqual(Object.keys(a.nested).length, 1);
});
it('throws on circular data', function () {
try {
var a = {};
@@ -59,36 +40,36 @@ describe('utils.js', function () {
});
});
describe('reply_in_order', function () {
describe('replyInOrder', function () {
var err_count = 0;
var res_count = 0;
var errCount = 0;
var resCount = 0;
var emitted = false;
var clientMock = {
emit: function () { emitted = true; },
offline_queue: new Queue(),
command_queue: new Queue()
offlineQueue: new Queue(),
commandQueue: new Queue()
};
var create_command_obj = function () {
var createCommandObj = function () {
return {
callback: function (err, res) {
if (err) err_count++;
else res_count++;
if (err) errCount++;
else resCount++;
}
};
};
beforeEach(function () {
clientMock.offline_queue.clear();
clientMock.command_queue.clear();
err_count = 0;
res_count = 0;
clientMock.offlineQueue.clear();
clientMock.commandQueue.clear();
errCount = 0;
resCount = 0;
emitted = false;
});
it('no elements in either queue. Reply in the next tick with callback', function (done) {
var called = false;
utils.reply_in_order(clientMock, function () {
utils.replyInOrder(clientMock, function () {
called = true;
done();
}, null, null);
@@ -97,7 +78,7 @@ describe('utils.js', function () {
it('no elements in either queue. Reply in the next tick without callback', function (done) {
assert(!emitted);
utils.reply_in_order(clientMock, null, new Error('tada'));
utils.replyInOrder(clientMock, null, new Error('tada'));
assert(!emitted);
setTimeout(function () {
assert(emitted);
@@ -105,48 +86,48 @@ describe('utils.js', function () {
}, 1);
});
it('elements in the offline queue. Reply after the offline queue is empty and respect the command_obj callback', function (done) {
clientMock.offline_queue.push(create_command_obj(), create_command_obj());
utils.reply_in_order(clientMock, function () {
assert.strictEqual(clientMock.offline_queue.length, 0);
assert.strictEqual(res_count, 2);
it('elements in the offline queue. Reply after the offline queue is empty and respect the commandObj callback', function (done) {
clientMock.offlineQueue.push(createCommandObj(), createCommandObj());
utils.replyInOrder(clientMock, function () {
assert.strictEqual(clientMock.offlineQueue.length, 0);
assert.strictEqual(resCount, 2);
done();
}, null, null);
while (clientMock.offline_queue.length) clientMock.offline_queue.shift().callback(null, 'foo');
while (clientMock.offlineQueue.length) clientMock.offlineQueue.shift().callback(null, 'foo');
});
it('elements in the offline queue. Reply after the offline queue is empty and respect the command_obj error emit', function (done) {
clientMock.command_queue.push({}, create_command_obj(), {});
utils.reply_in_order(clientMock, function () {
assert.strictEqual(clientMock.command_queue.length, 0);
it('elements in the offline queue. Reply after the offline queue is empty and respect the commandObj error emit', function (done) {
clientMock.commandQueue.push({}, createCommandObj(), {});
utils.replyInOrder(clientMock, function () {
assert.strictEqual(clientMock.commandQueue.length, 0);
assert(emitted);
assert.strictEqual(err_count, 1);
assert.strictEqual(res_count, 0);
assert.strictEqual(errCount, 1);
assert.strictEqual(resCount, 0);
done();
}, null, null);
while (clientMock.command_queue.length) {
var command_obj = clientMock.command_queue.shift();
if (command_obj.callback) {
command_obj.callback(new Error('tada'));
while (clientMock.commandQueue.length) {
var commandObj = clientMock.commandQueue.shift();
if (commandObj.callback) {
commandObj.callback(new Error('tada'));
}
}
});
it('elements in the offline queue and the command_queue. Reply all other commands got handled respect the command_obj', function (done) {
clientMock.command_queue.push(create_command_obj(), create_command_obj());
clientMock.offline_queue.push(create_command_obj(), {});
utils.reply_in_order(clientMock, function (err, res) {
assert.strictEqual(clientMock.command_queue.length, 0);
assert.strictEqual(clientMock.offline_queue.length, 0);
it('elements in the offline queue and the commandQueue. Reply all other commands got handled respect the commandObj', function (done) {
clientMock.commandQueue.push(createCommandObj(), createCommandObj());
clientMock.offlineQueue.push(createCommandObj(), {});
utils.replyInOrder(clientMock, function (err, res) {
assert.strictEqual(clientMock.commandQueue.length, 0);
assert.strictEqual(clientMock.offlineQueue.length, 0);
assert(!emitted);
assert.strictEqual(res_count, 3);
assert.strictEqual(resCount, 3);
done();
}, null, null);
while (clientMock.offline_queue.length) {
clientMock.command_queue.push(clientMock.offline_queue.shift());
while (clientMock.offlineQueue.length) {
clientMock.commandQueue.push(clientMock.offlineQueue.shift());
}
while (clientMock.command_queue.length) {
clientMock.command_queue.shift().callback(null, 'hello world');
while (clientMock.commandQueue.length) {
clientMock.commandQueue.shift().callback(null, 'hello world');
}
});
});