Browse Source

Merge pull request #807 from fintura/master

Add jshint and fix some tests
greenkeeper-update-all
Ruben Bridgewater 9 years ago
parent
commit
62f9a0cf63
  1. 1
      .gitignore
  2. 4
      .jshintignore
  3. 24
      .jshintrc
  4. 2
      .travis.yml
  5. 5
      benches/re_sub_test.js
  6. 2
      benches/stress/pubsub/pub.js
  7. 3
      benches/stress/pubsub/server.js
  8. 2
      benches/stress/rpushblpop/pub.js
  9. 3
      benches/stress/rpushblpop/server.js
  10. 68
      benches/stress/speed/speed.js
  11. 2
      connection_breaker.js
  12. 56
      diff_multi_bench_output.js
  13. 2
      examples/unix_socket.js
  14. 54
      index.js
  15. 9
      package.json
  16. 10
      test/auth.spec.js
  17. 2
      test/commands/blpop.spec.js
  18. 15
      test/commands/client.spec.js
  19. 3
      test/commands/dbsize.spec.js
  20. 3
      test/commands/del.spec.js
  21. 6
      test/commands/eval.spec.js
  22. 3
      test/commands/exits.spec.js
  23. 5
      test/commands/expire.spec.js
  24. 2
      test/commands/flushdb.spec.js
  25. 3
      test/commands/get.spec.js
  26. 3
      test/commands/getset.spec.js
  27. 2
      test/commands/hgetall.spec.js
  28. 3
      test/commands/hincrby.spec.js
  29. 3
      test/commands/hlen.spec.js
  30. 5
      test/commands/hmget.spec.js
  31. 14
      test/commands/hmset.spec.js
  32. 12
      test/commands/hset.spec.js
  33. 4
      test/commands/incr.spec.js
  34. 2
      test/commands/keys.spec.js
  35. 2
      test/commands/mget.spec.js
  36. 36
      test/commands/mset.spec.js
  37. 3
      test/commands/msetnx.spec.js
  38. 11
      test/commands/multi.spec.js
  39. 2
      test/commands/randomkey.test.js
  40. 3
      test/commands/rename.spec.js
  41. 5
      test/commands/renamenx.spec.js
  42. 2
      test/commands/sadd.spec.js
  43. 3
      test/commands/scard.spec.js
  44. 21
      test/commands/script.spec.js
  45. 2
      test/commands/sdiff.spec.js
  46. 2
      test/commands/sdiffstore.spec.js
  47. 5
      test/commands/select.spec.js
  48. 25
      test/commands/set.spec.js
  49. 2
      test/commands/setex.spec.js
  50. 4
      test/commands/setnx.spec.js
  51. 2
      test/commands/sinter.spec.js
  52. 2
      test/commands/sinterstore.spec.js
  53. 3
      test/commands/sismember.spec.js
  54. 2
      test/commands/slowlog.spec.js
  55. 2
      test/commands/smembers.spec.js
  56. 3
      test/commands/smove.spec.js
  57. 4
      test/commands/sort.spec.js
  58. 2
      test/commands/spop.spec.js
  59. 2
      test/commands/srem.spec.js
  60. 2
      test/commands/sunion.spec.js
  61. 2
      test/commands/sunionstore.spec.js
  62. 4
      test/commands/ttl.spec.js
  63. 3
      test/commands/type.spec.js
  64. 19
      test/commands/watch.spec.js
  65. 22
      test/helper.js
  66. 4
      test/lib/config.js
  67. 48
      test/lib/redis-process.js
  68. 4
      test/lib/unref.js
  69. 58
      test/node_redis.spec.js
  70. 2
      test/parser/javascript.spec.js
  71. 27
      test/pubsub.spec.js
  72. 2
      test/queue.spec.js

1
.gitignore

@ -2,3 +2,4 @@ node_modules
.tern-port .tern-port
.nyc_output .nyc_output
coverage coverage
npm-debug.log

4
.jshintignore

@ -0,0 +1,4 @@
node_modules/**
coverage/**
**.md
**.log

24
.jshintrc

@ -0,0 +1,24 @@
{
"eqeqeq": true, // Prohibits the use of == and != in favor of === and !==
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`
"undef": true, // Require all non-global variables be declared before they are used.
"unused": "vars", // Warn unused variables, but not unused params
"strict": true, // Require `use strict` pragma in every file.
"nonbsp": true, // don't allow non utf-8 pages to break
"forin": true, // don't allow not filtert for in loops
"freeze": true, // prohibit overwriting prototypes of native objects
"nonew": true, // prohibit use of constructors with new when not assigning to a variable
"maxdepth": 6,
"latedef": true,
"maxparams": 5,
// Environment options
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"mocha": true,
"overrides": {
"examples/*.js": {
"unused": false
}
}
}

2
.travis.yml

@ -13,4 +13,4 @@ node_js:
- "0.12" - "0.12"
- "4.0" - "4.0"
- "iojs" - "iojs"
after_success: npm run coverage after_success: npm run coveralls

5
benches/re_sub_test.js

@ -1,8 +1,7 @@
'use strict'; 'use strict';
var client = require('../index').createClient() var client = require('../index').createClient();
, client2 = require('../index').createClient() var client2 = require('../index').createClient();
, assert = require('assert');
client.once('subscribe', function (channel, count) { client.once('subscribe', function (channel, count) {
client.unsubscribe('x'); client.unsubscribe('x');

2
benches/stress/pubsub/pub.js

@ -3,8 +3,8 @@
var freemem = require('os').freemem; var freemem = require('os').freemem;
var profiler = require('v8-profiler'); var profiler = require('v8-profiler');
var codec = require('../codec'); var codec = require('../codec');
var sent = 0; var sent = 0;
var exec;
var pub = require('redis').createClient(null, null, { var pub = require('redis').createClient(null, null, {
//command_queue_high_water: 5, //command_queue_high_water: 5,

3
benches/stress/pubsub/server.js

@ -6,12 +6,11 @@ var codec = require('../codec');
var id = Math.random(); var id = Math.random();
var recv = 0; var recv = 0;
var sub = require('redis').createClient() require('redis').createClient()
.on('ready', function() { .on('ready', function() {
this.subscribe('timeline'); this.subscribe('timeline');
}) })
.on('message', function(channel, message) { .on('message', function(channel, message) {
var self = this;
if (message) { if (message) {
message = codec.decode(message); message = codec.decode(message);
++recv; ++recv;

2
benches/stress/rpushblpop/pub.js

@ -6,6 +6,8 @@ var codec = require('../codec');
var sent = 0; var sent = 0;
var exec;
var pub = require('redis').createClient(null, null, { var pub = require('redis').createClient(null, null, {
//command_queue_high_water: 5, //command_queue_high_water: 5,
//command_queue_low_water: 1 //command_queue_low_water: 1

3
benches/stress/rpushblpop/server.js

@ -7,7 +7,8 @@ var id = Math.random();
var recv = 0; var recv = 0;
var cmd = require('redis').createClient(); var cmd = require('redis').createClient();
var sub = require('redis').createClient()
require('redis').createClient()
.on('ready', function() { .on('ready', function() {
this.emit('timeline'); this.emit('timeline');
}) })

68
benches/stress/speed/speed.js

@ -16,6 +16,40 @@ var codec = {
var obj, l; var obj, l;
function run(obj, codec) {
var t1 = Date.now();
var n = 10000;
for (var i = 0; i < n; ++i) {
codec.decode(l = codec.encode(obj));
}
var t2 = Date.now();
//console.log('DONE', n*1000/(t2-t1), 'codecs/sec, length=', l.length);
return [n*1000/(t2-t1), l.length];
}
function series(obj, cname, n) {
var rate = 0;
var len = 0;
for (var i = 0; i < n; ++i) {
var r = run(obj, codec[cname]);
rate += r[0];
len += r[1];
}
rate /= n;
len /= n;
console.log(cname + ' ' + rate + ' ' + len);
return [rate, len];
}
function forObj(obj) {
var r = {
JSON: series(obj, 'JSON', 20),
msgpack: series(obj, 'msgpack', 20),
bison: series(obj, 'bison', 20)
};
return r;
}
var s = '0'; var s = '0';
for (var i = 0; i < 12; ++i) s += s; for (var i = 0; i < 12; ++i) s += s;
@ -50,37 +84,3 @@ obj = {
rand: [] rand: []
}; };
forObj(obj); forObj(obj);
function run(obj, codec) {
var t1 = Date.now();
var n = 10000;
for (var i = 0; i < n; ++i) {
codec.decode(l = codec.encode(obj));
}
var t2 = Date.now();
//console.log('DONE', n*1000/(t2-t1), 'codecs/sec, length=', l.length);
return [n*1000/(t2-t1), l.length];
}
function series(obj, cname, n) {
var rate = 0;
var len = 0;
for (var i = 0; i < n; ++i) {
var r = run(obj, codec[cname]);
rate += r[0];
len += r[1];
}
rate /= n;
len /= n;
console.log(cname + ' ' + rate + ' ' + len);
return [rate, len];
}
function forObj(obj) {
var r = {
JSON: series(obj, 'JSON', 20),
msgpack: series(obj, 'msgpack', 20),
bison: series(obj, 'bison', 20)
};
return r;
}

2
connection_breaker.js

@ -42,8 +42,6 @@ server.listen(6479);
var redis = require('./'); var redis = require('./');
var port = 6479;
var client = redis.createClient(6479, 'localhost'); var client = redis.createClient(6479, 'localhost');
function iter() { function iter() {

56
diff_multi_bench_output.js

@ -2,9 +2,9 @@
'use strict'; 'use strict';
var colors = require('colors'), /* jshint -W079: Ignore redefinitions (before & after) */
fs = require('fs'),
_ = require('underscore'), var fs = require('fs'),
metrics = require('metrics'), metrics = require('metrics'),
// `node diff_multi_bench_output.js before.txt after.txt` // `node diff_multi_bench_output.js before.txt after.txt`
@ -30,6 +30,28 @@ console.log('Comparing before,', before.green, '(', before_lines.length,
var total_ops = new metrics.Histogram.createUniformHistogram(); var total_ops = new metrics.Histogram.createUniformHistogram();
function is_whitespace(s) {
return !!s.trim();
}
function parseInt10(s) {
return parseInt(s, 10);
}
// green if greater than 0, red otherwise
function humanize_diff(num, unit) {
unit = unit || "";
if (num > 0) {
return ('+' + num + unit).green;
}
return ('' + num + unit).red;
}
function command_name(words) {
var line = words.join(' ');
return line.substr(0, line.indexOf(','));
}
before_lines.forEach(function(b, i) { before_lines.forEach(function(b, i) {
var a = after_lines[i]; var a = after_lines[i];
if (!a || !b || !b.trim() || !a.trim()) { if (!a || !b || !b.trim() || !a.trim()) {
@ -60,33 +82,11 @@ before_lines.forEach(function(b, i) {
pct = humanize_diff(pct, '%'); pct = humanize_diff(pct, '%');
console.log( console.log(
// name of test // name of test
command_name(a_words) === command_name(b_words) command_name(a_words) === command_name(b_words) ?
? command_name(a_words) + ':' command_name(a_words) + ':' :
: '404:', '404:',
// results of test // results of test
ops.join(' -> '), 'ops/sec (∆', delta, pct, ')'); ops.join(' -> '), 'ops/sec (∆', delta, pct, ')');
}); });
console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean().toPrecision(6))); console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean().toPrecision(6)));
function is_whitespace(s) {
return !!s.trim();
}
function parseInt10(s) {
return parseInt(s, 10);
}
// green if greater than 0, red otherwise
function humanize_diff(num, unit) {
unit = unit || "";
if (num > 0) {
return ('+' + num + unit).green;
}
return ('' + num + unit).red;
}
function command_name(words) {
var line = words.join(' ');
return line.substr(0, line.indexOf(','));
}

2
examples/unix_socket.js

@ -27,5 +27,5 @@ function done() {
setTimeout(function () { setTimeout(function () {
console.log("Taking snapshot."); console.log("Taking snapshot.");
var snap = profiler.takeSnapshot(); profiler.takeSnapshot();
}, 5000); }, 5000);

54
index.js

@ -1,7 +1,5 @@
'use strict'; 'use strict';
/*global Buffer require exports console setTimeout */
var net = require("net"), var net = require("net"),
URL = require("url"), URL = require("url"),
util = require("util"), util = require("util"),
@ -616,7 +614,7 @@ RedisClient.prototype.return_reply = function (reply) {
type = reply[0].toString(); type = reply[0].toString();
} }
if (this.pub_sub_mode && (type == 'message' || type == 'pmessage')) { if (this.pub_sub_mode && (type === 'message' || type === 'pmessage')) {
debug("received pubsub message"); debug("received pubsub message");
} }
else { else {
@ -957,7 +955,7 @@ RedisClient.prototype.select = function (db, callback) {
if (err === null) { if (err === null) {
self.selected_db = db; self.selected_db = db;
} }
if (typeof(callback) === 'function') { if (typeof callback === 'function') {
callback(err, res); callback(err, res);
} else if (err) { } else if (err) {
self.emit('error', err); self.emit('error', err);
@ -1172,30 +1170,6 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
}); });
}; };
exports.createClient = function(port_arg, host_arg, options) {
if (typeof port_arg === 'object' || port_arg === undefined) {
options = port_arg || options;
return createClient_tcp(default_port, default_host, options);
}
if (typeof port_arg === 'number' || typeof port_arg === 'string' && /^\d+$/.test(port_arg)) {
return createClient_tcp(port_arg, host_arg, options);
}
if (typeof port_arg === 'string') {
options = host_arg || {};
var parsed = URL.parse(port_arg, true, true);
if (parsed.hostname) {
if (parsed.auth) {
options.auth_pass = parsed.auth.split(':')[1];
}
return createClient_tcp(parsed.port, parsed.hostname, options);
}
return createClient_unix(port_arg, options);
}
throw new Error('unknown type of connection in createClient()');
};
var createClient_unix = function(path, options){ var createClient_unix = function(path, options){
var cnxOptions = { var cnxOptions = {
path: path path: path
@ -1224,6 +1198,30 @@ var createClient_tcp = function (port_arg, host_arg, options) {
return redis_client; return redis_client;
}; };
exports.createClient = function(port_arg, host_arg, options) {
if (typeof port_arg === 'object' || port_arg === undefined) {
options = port_arg || options;
return createClient_tcp(default_port, default_host, options);
}
if (typeof port_arg === 'number' || typeof port_arg === 'string' && /^\d+$/.test(port_arg)) {
return createClient_tcp(port_arg, host_arg, options);
}
if (typeof port_arg === 'string') {
options = host_arg || {};
var parsed = URL.parse(port_arg, true, true);
if (parsed.hostname) {
if (parsed.auth) {
options.auth_pass = parsed.auth.split(':')[1];
}
return createClient_tcp(parsed.port, parsed.hostname, options);
}
return createClient_unix(port_arg, options);
}
throw new Error('unknown type of connection in createClient()');
};
exports.print = function (err, reply) { exports.print = function (err, reply) {
if (err) { if (err) {
console.log("Error: " + err); console.log("Error: " + err);

9
package.json

@ -10,19 +10,20 @@
"license": "MIT", "license": "MIT",
"main": "./index.js", "main": "./index.js",
"scripts": { "scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls", "coveralls": "nyc report --reporter=text-lcov | coveralls",
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000" "coverage": "nyc report --reporter=html",
"test": "./node_modules/.bin/jshint * && nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000",
"jshint": "./node_modules/.bin/jshint *"
}, },
"devDependencies": { "devDependencies": {
"async": "^1.3.0", "async": "^1.3.0",
"colors": "~0.6.0-1",
"coveralls": "^2.11.2", "coveralls": "^2.11.2",
"hiredis": "^0.4.1", "hiredis": "^0.4.1",
"jshint": "^2.8.0",
"metrics": ">=0.1.5", "metrics": ">=0.1.5",
"mocha": "^2.2.5", "mocha": "^2.2.5",
"nyc": "^3.0.0", "nyc": "^3.0.0",
"tcp-port-used": "^0.1.2", "tcp-port-used": "^0.1.2",
"underscore": "~1.4.4",
"uuid": "^2.0.1" "uuid": "^2.0.1"
}, },
"repository": { "repository": {

10
test/auth.spec.js

@ -1,7 +1,8 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("./lib/config"); var config = require("./lib/config");
var helper = require('./helper') var helper = require('./helper');
var path = require('path');
var redis = config.redis; var redis = config.redis;
describe("client authentication", function () { describe("client authentication", function () {
@ -35,7 +36,7 @@ describe("client authentication", function () {
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
client.once('error', function (error) { client.once('error', function (error) {
assert.ok(/ERR invalid password/.test(error)) assert.ok(/ERR invalid password/.test(error));
return done(); return done();
}); });
@ -46,7 +47,8 @@ describe("client authentication", function () {
it('allows auth to be provided as part of redis url', function (done) { it('allows auth to be provided as part of redis url', function (done) {
client = redis.createClient('redis://foo:' + auth + '@' + config.HOST[ip] + ':' + config.PORT); client = redis.createClient('redis://foo:' + auth + '@' + config.HOST[ip] + ':' + config.PORT);
client.on("ready", function () { client.on("ready", function () {
return done() }); return done();
});
}); });
} }

2
test/commands/blpop.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

15
test/commands/client.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -17,11 +19,10 @@ describe("The 'client' method", function () {
client.once("connect", function () { client.once("connect", function () {
client.flushdb(function (err) { client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 4, 0])) { if (!helper.serverVersionAtLeast(client, [2, 4, 0])) {
err = Error('script not supported in redis <= 2.4.0') err = Error('script not supported in redis <= 2.4.0');
} }
return done(err); return done(err);
});
})
}); });
}); });
@ -37,15 +38,15 @@ describe("The 'client' method", function () {
it("lists connected clients when invoked with multi's chaining syntax", function (done) { it("lists connected clients when invoked with multi's chaining syntax", function (done) {
client.multi().client("list").exec(function(err, results) { client.multi().client("list").exec(function(err, results) {
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString()); assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
return done() return done();
}) });
}); });
it("lists connected clients when invoked with multi's array syntax", function (done) { it("lists connected clients when invoked with multi's array syntax", function (done) {
client.multi().client("list").exec(function(err, results) { client.multi().client("list").exec(function(err, results) {
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString()); assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
return done() return done();
}) });
}); });
}); });
}); });

3
test/commands/dbsize.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');

3
test/commands/del.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

6
test/commands/eval.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var crypto = require("crypto"); var crypto = require("crypto");
@ -17,10 +19,10 @@ describe("The 'eval' method", function () {
client.once("connect", function () { client.once("connect", function () {
client.flushdb(function (err) { client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 5, 0])) { if (!helper.serverVersionAtLeast(client, [2, 5, 0])) {
err = Error('exec not supported in redis <= 2.5.0') err = Error('exec not supported in redis <= 2.5.0');
} }
return done(err); return done(err);
}) });
}); });
}); });

3
test/commands/exits.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

5
test/commands/expire.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;
@ -23,7 +24,7 @@ describe("The 'expire' method", function () {
client.EXPIRE(["expiry key", "1"], helper.isNumber(1)); client.EXPIRE(["expiry key", "1"], helper.isNumber(1));
setTimeout(function () { setTimeout(function () {
client.exists(["expiry key"], helper.isNumber(0, done)); client.exists(["expiry key"], helper.isNumber(0, done));
}, 1500); }, 1100);
}); });
afterEach(function () { afterEach(function () {

2
test/commands/flushdb.spec.js

@ -1,3 +1,5 @@
'use strict';
var async = require('async'); var async = require('async');
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");

3
test/commands/get.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');

3
test/commands/getset.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');

2
test/commands/hgetall.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

3
test/commands/hincrby.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

3
test/commands/hlen.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

5
test/commands/hmget.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -16,8 +18,7 @@ describe("The 'hmget' method", function () {
client.once("error", done); client.once("error", done);
client.once("connect", function () { client.once("connect", function () {
client.flushdb(); client.flushdb();
client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"}, helper.isString('OK')); client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"}, helper.isString('OK', done));
return done();
}); });
}); });

14
test/commands/hmset.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -25,7 +27,7 @@ describe("The 'hmset' method", function () {
assert.equal(obj['0123456789'], 'abcdefghij'); assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value'); assert.equal(obj['some manner of key'], 'a type of value');
return done(err); return done(err);
}) });
}); });
it('handles object-style syntax', function (done) { it('handles object-style syntax', function (done) {
@ -34,7 +36,7 @@ describe("The 'hmset' method", function () {
assert.equal(obj['0123456789'], 'abcdefghij'); assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value'); assert.equal(obj['some manner of key'], 'a type of value');
return done(err); return done(err);
}) });
}); });
it('handles object-style syntax and the key being a number', function (done) { it('handles object-style syntax and the key being a number', function (done) {
@ -58,7 +60,7 @@ describe("The 'hmset' method", function () {
client.HMSET(hash, 99, 'banana', 'test', 25); client.HMSET(hash, 99, 'banana', 'test', 25);
client.HGETALL(hash, function (err, obj) { client.HGETALL(hash, function (err, obj) {
assert.equal(obj['99'], 'banana'); assert.equal(obj['99'], 'banana');
assert.equal(obj['test'], '25'); assert.equal(obj.test, '25');
return done(err); return done(err);
}); });
}); });
@ -67,7 +69,7 @@ describe("The 'hmset' method", function () {
client.HMSET([hash, 99, 'banana', 'test', 25]); client.HMSET([hash, 99, 'banana', 'test', 25]);
client.HGETALL(hash, function (err, obj) { client.HGETALL(hash, function (err, obj) {
assert.equal(obj['99'], 'banana'); assert.equal(obj['99'], 'banana');
assert.equal(obj['test'], '25'); assert.equal(obj.test, '25');
return done(err); return done(err);
}); });
}); });
@ -76,7 +78,7 @@ describe("The 'hmset' method", function () {
client.HMSET([hash, 99, 'banana', 'test', 25], helper.isString('OK')); client.HMSET([hash, 99, 'banana', 'test', 25], helper.isString('OK'));
client.HGETALL(hash, function (err, obj) { client.HGETALL(hash, function (err, obj) {
assert.equal(obj['99'], 'banana'); assert.equal(obj['99'], 'banana');
assert.equal(obj['test'], '25'); assert.equal(obj.test, '25');
return done(err); return done(err);
}); });
}); });
@ -87,7 +89,7 @@ describe("The 'hmset' method", function () {
assert.equal(obj['0123456789'], 'abcdefghij'); assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value'); assert.equal(obj['some manner of key'], 'a type of value');
return done(err); return done(err);
}) });
}); });
afterEach(function () { afterEach(function () {

12
test/commands/hset.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -45,11 +47,11 @@ describe("The 'hset' method", function () {
}); });
it('does not error when a buffer and array are set as fields on the same hash', function (done) { it('does not error when a buffer and array are set as fields on the same hash', function (done) {
var hash = "test hash" var hash = "test hash";
var field1 = "buffer" var field1 = "buffer";
var value1 = new Buffer("abcdefghij") var value1 = new Buffer("abcdefghij");
var field2 = "array" var field2 = "array";
var value2 = ["array contents"] var value2 = ["array contents"];
client.HMSET(hash, field1, value1, field2, value2, helper.isString("OK", done)); client.HMSET(hash, field1, value1, field2, value2, helper.isString("OK", done));
}); });

4
test/commands/incr.spec.js

@ -1,9 +1,9 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');
var redis = config.redis; var redis = config.redis;
var uuid = require('uuid');
describe("The 'incr' method", function () { describe("The 'incr' method", function () {

2
test/commands/keys.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var crypto = require("crypto"); var crypto = require("crypto");

2
test/commands/mget.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

36
test/commands/mset.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');
@ -59,11 +60,15 @@ describe("The 'mset' method", function () {
describe("and a callback is specified", function () { describe("and a callback is specified", function () {
describe("with valid parameters", function () { describe("with valid parameters", function () {
it("sets the value correctly", function (done) { it("sets the value correctly", function (done) {
client.mset(key, value, key2, value2); client.mset(key, value, key2, value2, function(err) {
if (err) {
return done(err);
}
client.get(key, helper.isString(value)); client.get(key, helper.isString(value));
client.get(key2, helper.isString(value2, done)); client.get(key2, helper.isString(value2, done));
}); });
}); });
});
describe("with undefined 'key' parameter and missing 'value' parameter", function () { describe("with undefined 'key' parameter and missing 'value' parameter", function () {
it("reports an error", function (done) { it("reports an error", function (done) {
@ -74,22 +79,14 @@ describe("The 'mset' method", function () {
}); });
}); });
describe("with undefined 'key' and defined 'value' parameters", function () {
it("reports an error", function () {
client.mset(undefined, value, undefined, value2, function (err, res) {
helper.isError()(err, null);
done();
});
});
});
}); });
describe("and no callback is specified", function () { describe("and no callback is specified", function () {
describe("with valid parameters", function () { describe("with valid parameters", function () {
it("sets the value correctly", function (done) { it("sets the value correctly", function (done) {
client.mset(key, value, key2, value2); client.mset(key, value2, key2, value);
client.get(key, helper.isString(value)); client.get(key, helper.isString(value2));
client.get(key2, helper.isString(value2, done)); client.get(key2, helper.isString(value, done));
}); });
}); });
@ -107,19 +104,6 @@ describe("The 'mset' method", function () {
client.mset(); client.mset();
}); });
}); });
describe("with undefined 'key' and defined 'value' parameters", function () {
it("throws an error", function () {
var mochaListener = helper.removeMochaListener();
process.once('uncaughtException', function (err) {
process.on('uncaughtException', mochaListener);
helper.isError()(err, null);
});
client.mset(undefined, value, undefined, value2);
});
});
}); });
}); });
}); });

3
test/commands/msetnx.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

11
test/commands/multi.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');
@ -49,7 +50,7 @@ describe("The 'multi' method", function () {
client.once("connect", function () { client.once("connect", function () {
client.flushdb(function (err) { client.flushdb(function (err) {
return done(err); return done(err);
}) });
}); });
}); });
@ -58,7 +59,7 @@ describe("The 'multi' method", function () {
}); });
it('roles back a transaction when one command in a sequence of commands fails', function (done) { it('roles back a transaction when one command in a sequence of commands fails', function (done) {
var name = "MULTI_1", multi1, multi2; var multi1, multi2;
// Provoke an error at queue time // Provoke an error at queue time
multi1 = client.multi(); multi1 = client.multi();
@ -91,7 +92,7 @@ describe("The 'multi' method", function () {
// I'm unclear as to the difference between this test in the test above, // I'm unclear as to the difference between this test in the test above,
// perhaps @mranney can clarify? // perhaps @mranney can clarify?
it('roles back a transaction when an error was provoked at queue time', function (done) { it('roles back a transaction when an error was provoked at queue time', function (done) {
multi1 = client.multi(); var multi1 = client.multi();
multi1.mset("multifoo_8", "10", "multibar_8", "20", helper.isString("OK")); multi1.mset("multifoo_8", "10", "multibar_8", "20", helper.isString("OK"));
multi1.set("foo2", helper.isError()); multi1.set("foo2", helper.isError());
multi1.set("foo3", helper.isError()); multi1.set("foo3", helper.isError());
@ -108,7 +109,7 @@ describe("The 'multi' method", function () {
} }
// Confirm that the previous command, while containing an error, still worked. // Confirm that the previous command, while containing an error, still worked.
multi2 = client.multi(); var multi2 = client.multi();
multi2.incr("multibar_8", helper.isNumber(multibar_expected)); multi2.incr("multibar_8", helper.isNumber(multibar_expected));
multi2.incr("multifoo_8", helper.isNumber(multifoo_expected)); multi2.incr("multifoo_8", helper.isNumber(multifoo_expected));
multi2.exec(function (err, replies) { multi2.exec(function (err, replies) {

2
test/commands/randomkey.test.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

3
test/commands/rename.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

5
test/commands/renamenx.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;
@ -31,7 +32,7 @@ describe("The 'renamenx' method", function () {
client.renamenx('foo', 'foo2', helper.isNumber(0)); client.renamenx('foo', 'foo2', helper.isNumber(0));
client.exists('foo', helper.isNumber(1)); client.exists('foo', helper.isNumber(1));
client.exists(['foo2'], helper.isNumber(1, done)); client.exists(['foo2'], helper.isNumber(1, done));
}) });
afterEach(function () { afterEach(function () {
client.end(); client.end();

2
test/commands/sadd.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

3
test/commands/scard.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

21
test/commands/script.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var crypto = require("crypto"); var crypto = require("crypto");
@ -19,11 +21,10 @@ describe("The 'script' method", function () {
client.once("connect", function () { client.once("connect", function () {
client.flushdb(function (err) { client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 6, 0])) { if (!helper.serverVersionAtLeast(client, [2, 6, 0])) {
err = Error('script not supported in redis <= 2.6.0') err = Error('script not supported in redis <= 2.6.0');
} }
return done(err); return done(err);
});
})
}); });
}); });
@ -40,21 +41,21 @@ describe("The 'script' method", function () {
it('allows a loaded script to be evaluated', function (done) { it('allows a loaded script to be evaluated', function (done) {
client.evalsha(commandSha, 0, helper.isString('99', done)); client.evalsha(commandSha, 0, helper.isString('99', done));
}) });
it('allows a script to be loaded as part of a chained transaction', function (done) { it('allows a script to be loaded as part of a chained transaction', function (done) {
client.multi().script("load", command).exec(function(err, result) { client.multi().script("load", command).exec(function(err, result) {
assert.strictEqual(result[0], commandSha); assert.strictEqual(result[0], commandSha);
return done() return done();
}) });
}) });
it("allows a script to be loaded using a transaction's array syntax", function (done) { it("allows a script to be loaded using a transaction's array syntax", function (done) {
client.multi([['script', 'load', command]]).exec(function(err, result) { client.multi([['script', 'load', command]]).exec(function(err, result) {
assert.strictEqual(result[0], commandSha); assert.strictEqual(result[0], commandSha);
return done() return done();
}) });
}) });
}); });
}); });
}); });

2
test/commands/sdiff.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

2
test/commands/sdiffstore.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

5
test/commands/select.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');
@ -69,7 +70,7 @@ describe("The 'select' method", function () {
it("emits an error", function (done) { it("emits an error", function (done) {
assert.strictEqual(client.selected_db, null, "default db should be null"); assert.strictEqual(client.selected_db, null, "default db should be null");
client.select(9999, function (err) { client.select(9999, function (err) {
assert.equal(err.message, 'ERR invalid DB index') assert.equal(err.message, 'ERR invalid DB index');
return done(); return done();
}); });
}); });

25
test/commands/set.spec.js

@ -1,4 +1,5 @@
var async = require('async'); 'use strict';
var assert = require('assert'); var assert = require('assert');
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require('../helper'); var helper = require('../helper');
@ -75,15 +76,6 @@ describe("The 'set' method", function () {
}); });
}); });
}); });
describe("with undefined 'key' and defined 'value' parameters", function () {
it("reports an error", function () {
client.set(undefined, value, function (err, res) {
helper.isError()(err, null);
done();
});
});
});
}); });
describe("and no callback is specified", function () { describe("and no callback is specified", function () {
@ -131,19 +123,6 @@ describe("The 'set' method", function () {
}, 100); }, 100);
}); });
}); });
describe("with undefined 'key' and defined 'value' parameters", function () {
it("throws an error", function () {
var mochaListener = helper.removeMochaListener();
process.once('uncaughtException', function (err) {
process.on('uncaughtException', mochaListener);
helper.isError()(err, null);
});
client.set(undefined, value);
});
});
}); });
}); });
}); });

2
test/commands/setex.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

4
test/commands/setnx.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;
@ -27,7 +28,6 @@ describe("The 'setnx' method", function () {
client.set('foo', 'bar', helper.isString('OK')); client.set('foo', 'bar', helper.isString('OK'));
client.setnx('foo', 'banana', helper.isNumber(0)); client.setnx('foo', 'banana', helper.isNumber(0));
client.get('foo', helper.isString('bar', done)); client.get('foo', helper.isString('bar', done));
return done();
}); });
afterEach(function () { afterEach(function () {

2
test/commands/sinter.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

2
test/commands/sinterstore.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

3
test/commands/sismember.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

2
test/commands/slowlog.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

2
test/commands/smembers.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

3
test/commands/smove.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

4
test/commands/sort.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -15,7 +17,7 @@ describe("The 'sort' method", function () {
client.once("error", done); client.once("error", done);
client.once("connect", function () { client.once("connect", function () {
client.flushdb(); client.flushdb();
setupData(client, done) setupData(client, done);
}); });
}); });

2
test/commands/spop.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

2
test/commands/srem.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

2
test/commands/sunion.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

2
test/commands/sunionstore.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");

4
test/commands/ttl.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -26,7 +28,7 @@ describe("The 'ttl' method", function () {
assert.ok(ttl > 50 && ttl <= 100); assert.ok(ttl > 50 && ttl <= 100);
return done(err); return done(err);
}); });
}, 500); }, 200);
}); });
afterEach(function () { afterEach(function () {

3
test/commands/type.spec.js

@ -1,4 +1,5 @@
var assert = require("assert"); 'use strict';
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
var redis = config.redis; var redis = config.redis;

19
test/commands/watch.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("../lib/config"); var config = require("../lib/config");
var helper = require("../helper"); var helper = require("../helper");
@ -18,11 +20,10 @@ describe("The 'watch' method", function () {
client.once("connect", function () { client.once("connect", function () {
client.flushdb(function (err) { client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 2, 0])) { if (!helper.serverVersionAtLeast(client, [2, 2, 0])) {
err = Error('some watch commands not supported in redis <= 2.2.0') err = Error('some watch commands not supported in redis <= 2.2.0');
} }
return done(err); return done(err);
});
})
}); });
}); });
@ -33,10 +34,10 @@ describe("The 'watch' method", function () {
it('does not execute transaction if watched key was modified prior to execution', function (done) { it('does not execute transaction if watched key was modified prior to execution', function (done) {
client.watch(watched); client.watch(watched);
client.incr(watched); client.incr(watched);
multi = client.multi(); var multi = client.multi();
multi.incr(watched); multi.incr(watched);
multi.exec(helper.isNull(done)); multi.exec(helper.isNull(done));
}) });
it('successfully modifies other keys independently of transaction', function (done) { it('successfully modifies other keys independently of transaction', function (done) {
client.set("unwatched", 200); client.set("unwatched", 200);
@ -45,17 +46,15 @@ describe("The 'watch' method", function () {
client.watch(watched); client.watch(watched);
client.incr(watched); client.incr(watched);
var multi = client.multi() client.multi().incr(watched).exec(function (err, replies) {
.incr(watched)
.exec(function (err, replies) {
assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null."); assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null.");
client.get("unwatched", function (err, reply) { client.get("unwatched", function (err, reply) {
assert.equal(reply, 200, "Expected 200, got " + reply); assert.equal(reply, 200, "Expected 200, got " + reply);
return done(err) return done(err);
});
}); });
}); });
})
}); });
}); });
}); });

22
test/helper.js

@ -1,9 +1,18 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var path = require('path'); var path = require('path');
var config = require("./lib/config"); var config = require("./lib/config");
var RedisProcess = require("./lib/redis-process"); var RedisProcess = require("./lib/redis-process");
var rp; var rp;
function startRedis (conf, done) {
RedisProcess.start(function (err, _rp) {
rp = _rp;
return done(err);
}, path.resolve(__dirname, conf));
}
// don't start redis every time we // don't start redis every time we
// include this helper file! // include this helper file!
if (!process.env.REDIS_TESTS_STARTED) { if (!process.env.REDIS_TESTS_STARTED) {
@ -11,7 +20,7 @@ if (!process.env.REDIS_TESTS_STARTED) {
before(function (done) { before(function (done) {
startRedis('./conf/redis.conf', done); startRedis('./conf/redis.conf', done);
}) });
after(function (done) { after(function (done) {
if (rp) rp.stop(done); if (rp) rp.stop(done);
@ -49,7 +58,7 @@ module.exports = {
}, },
isError: function (done) { isError: function (done) {
return function (err, results) { return function (err, results) {
assert.notEqual(err, null, "err is null, but an error is expected here."); assert(err instanceof Error, "err is not instance of 'Error', but an error is expected here.");
if (done) return done(); if (done) return done();
}; };
}, },
@ -108,11 +117,4 @@ module.exports = {
process.removeListener('uncaughtException', mochaListener); process.removeListener('uncaughtException', mochaListener);
return mochaListener; return mochaListener;
} }
} };
function startRedis (conf, done) {
RedisProcess.start(function (err, _rp) {
rp = _rp;
return done(err);
}, path.resolve(__dirname, conf));
}

4
test/lib/config.js

@ -1,3 +1,5 @@
'use strict';
// helpers for configuring a redis client in // helpers for configuring a redis client in
// its various modes, ipV6, ipV4, socket. // its various modes, ipV6, ipV4, socket.
var redis = require('../../index'); var redis = require('../../index');
@ -14,7 +16,7 @@ var config = {
opts = opts || {}; opts = opts || {};
if (ip.match(/\.sock/)) { if (ip.match(/\.sock/)) {
args.push(ip) args.push(ip);
} else { } else {
args.push(config.PORT); args.push(config.PORT);
args.push(config.HOST[ip]); args.push(config.HOST[ip]);

48
test/lib/redis-process.js

@ -1,3 +1,5 @@
'use strict';
// helper to start and stop the redis process. // helper to start and stop the redis process.
var cp = require('child_process'); var cp = require('child_process');
var config = require('./config'); var config = require('./config');
@ -5,6 +7,26 @@ var fs = require('fs');
var path = require('path'); var path = require('path');
var tcpPortUsed = require('tcp-port-used'); var tcpPortUsed = require('tcp-port-used');
// wait for redis to be listening in
// all three modes (ipv4, ipv6, socket).
function waitForRedis (available, cb) {
var ipV4 = false;
var id = setInterval(function () {
tcpPortUsed.check(config.PORT, '127.0.0.1')
.then(function (_ipV4) {
ipV4 = _ipV4;
return tcpPortUsed.check(config.PORT, '::1');
})
.then(function (ipV6) {
if (ipV6 === available && ipV4 === available &&
fs.existsSync('/tmp/redis.sock') === available) {
clearInterval(id);
return cb();
}
});
}, 100);
}
module.exports = { module.exports = {
start: function (done, conf) { start: function (done, conf) {
// spawn redis with our testing configuration. // spawn redis with our testing configuration.
@ -18,9 +40,9 @@ module.exports = {
console.error('failed to starting redis with exit code "' + code + '" ' + console.error('failed to starting redis with exit code "' + code + '" ' +
'stop any other redis processes currently running (' + 'stop any other redis processes currently running (' +
'hint: lsof -i :6379)'); 'hint: lsof -i :6379)');
process.exit(code) process.exit(code);
} }
}) });
// wait for redis to become available, by // wait for redis to become available, by
// checking the port we bind on. // checking the port we bind on.
@ -36,7 +58,7 @@ module.exports = {
} }
waitForRedis(false, function () { waitForRedis(false, function () {
return done(error); return done(error);
}) });
}); });
rp.kill("SIGTERM"); rp.kill("SIGTERM");
} }
@ -44,23 +66,3 @@ module.exports = {
}); });
} }
}; };
// wait for redis to be listening in
// all three modes (ipv4, ipv6, socket).
function waitForRedis (available, cb) {
var ipV4 = false;
var id = setInterval(function () {
tcpPortUsed.check(config.PORT, '127.0.0.1')
.then(function (_ipV4) {
ipV4 = _ipV4;
return tcpPortUsed.check(config.PORT, '::1');
})
.then(function (ipV6) {
if (ipV6 === available && ipV4 === available &&
fs.existsSync('/tmp/redis.sock') === available) {
clearInterval(id);
return cb();
}
});
}, 100);
}

4
test/lib/unref.js

@ -5,8 +5,8 @@
var redis = require("../../"); var redis = require("../../");
var HOST = process.argv[2] || '127.0.0.1'; var HOST = process.argv[2] || '127.0.0.1';
var PORT = process.argv[3] var PORT = process.argv[3];
var args = PORT ? [PORT, HOST] : [HOST] var args = PORT ? [PORT, HOST] : [HOST];
var c = redis.createClient.apply(redis, args); var c = redis.createClient.apply(redis, args);
c.unref(); c.unref();

58
test/node_redis.spec.js

@ -1,7 +1,9 @@
'use strict';
var async = require("async"); var async = require("async");
var assert = require("assert"); var assert = require("assert");
var config = require("./lib/config"); var config = require("./lib/config");
var helper = require('./helper') var helper = require('./helper');
var fork = require("child_process").fork; var fork = require("child_process").fork;
var redis = config.redis; var redis = config.redis;
@ -108,7 +110,7 @@ describe("The node_redis client", function () {
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
client.once("error", done); client.once("error", done);
client.once("connect", function () { client.once("connect", function () {
client.flushdb(done) client.flushdb(done);
}); });
}); });
@ -186,15 +188,12 @@ describe("The node_redis client", function () {
// Does not pass. // Does not pass.
// "Connection in subscriber mode, only subscriber commands may be used" // "Connection in subscriber mode, only subscriber commands may be used"
it("reconnects, unsubscribes, and can retrieve the pre-existing data", function (done) { it("reconnects, unsubscribes, and can retrieve the pre-existing data", function (done) {
client.on("reconnecting", function on_recon(params) {
client.on("ready", function on_connect() { client.on("ready", function on_connect() {
client.unsubscribe(helper.isNotError()); client.unsubscribe(helper.isNotError());
client.on('unsubscribe', function (channel, count) { client.on('unsubscribe', function (channel, count) {
// we should now be out of subscriber mode. // we should now be out of subscriber mode.
client.set('foo', 'bar', helper.isNumber(1)); client.set('foo', 'bar', helper.isString('OK', done));
return done();
});
}); });
}); });
@ -205,41 +204,6 @@ describe("The node_redis client", function () {
client.stream.destroy(); client.stream.destroy();
}); });
}); });
it("remains subscribed", function () {
var client2 = redis.createClient.apply(redis.createClient, args);
client.on("reconnecting", function on_recon(params) {
client.on("ready", function on_connect() {
async.parallel([function (cb) {
client.on("message", function (channel, message) {
try {
helper.isString("recon channel")(null, channel);
helper.isString("a test message")(null, message);
} catch (err) {
cb(err);
}
});
client2.subscribe("recon channel", function (err, res) {
if (err) {
cb(err);
return;
}
client2.publish("recon channel", "a test message");
});
}], function (err, results) {
done(err);
});
});
});
client.subscribe("recon channel", function (err, res) {
// Do not do this in normal programs. This is to simulate the server closing on us.
// For orderly shutdown in normal programs, do client.quit()
client.stream.destroy();
});
});
}); });
describe('domain', function () { describe('domain', function () {
@ -249,7 +213,7 @@ describe("The node_redis client", function () {
try { try {
domain = require('domain').create(); domain = require('domain').create();
} catch (err) { } catch (err) {
console.log("Skipping " + name + " because this version of node doesn't have domains."); console.log("Skipping test because this version of node doesn't have domains.");
return done(); return done();
} }
@ -257,14 +221,14 @@ describe("The node_redis client", function () {
domain.run(function () { domain.run(function () {
client.set('domain', 'value', function (err, res) { client.set('domain', 'value', function (err, res) {
assert.ok(process.domain); assert.ok(process.domain);
var notFound = res.not.existing.thing; // ohhh nooooo throw new Error('ohhhh noooo');
}); });
}); });
// this is the expected and desired behavior // this is the expected and desired behavior
domain.on('error', function (err) { domain.on('error', function (err) {
domain.exit(); domain.exit();
return done() return done();
}); });
} }
}); });
@ -316,7 +280,7 @@ describe("The node_redis client", function () {
}); });
client2.on("message", function (channel, data) { client2.on("message", function (channel, data) {
if (channel == name) { if (channel === name) {
assert.equal(data, "some message"); assert.equal(data, "some message");
throw Error('forced exception'); throw Error('forced exception');
} }
@ -678,7 +642,7 @@ describe("The node_redis client", function () {
}); });
it("sets upper bound on how long client waits before reconnecting", function (done) { it("sets upper bound on how long client waits before reconnecting", function (done) {
var time = new Date().getTime() var time = new Date().getTime();
var reconnecting = false; var reconnecting = false;
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
@ -736,7 +700,7 @@ describe("The node_redis client", function () {
}); });
assert.throws(function () { assert.throws(function () {
cli.set('foo', 'bar'); client.set('foo', 'bar');
}); });
assert.doesNotThrow(function () { assert.doesNotThrow(function () {

2
test/parser/javascript.spec.js

@ -1,4 +1,4 @@
/* global describe, it */ 'use strict';
var assert = require('assert'); var assert = require('assert');
var Parser = require("../../lib/parser/javascript").Parser; var Parser = require("../../lib/parser/javascript").Parser;

27
test/pubsub.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var config = require("./lib/config"); var config = require("./lib/config");
var helper = require("./helper"); var helper = require("./helper");
@ -10,10 +12,9 @@ describe("publish/subscribe", function () {
describe("using " + parser + " and " + ip, function () { describe("using " + parser + " and " + ip, function () {
var pub = null; var pub = null;
var sub = null; var sub = null;
var channel = "test channel" var channel = "test channel";
var channel2 = "test channel 2" var channel2 = "test channel 2";
var message = "test message" var message = "test message";
var hash = "test hash";
beforeEach(function (done) { beforeEach(function (done) {
var pubConnected; var pubConnected;
@ -45,7 +46,7 @@ describe("publish/subscribe", function () {
it('fires a subscribe event for each channel subscribed to', function (done) { it('fires a subscribe event for each channel subscribed to', function (done) {
sub.on("subscribe", function (chnl, count) { sub.on("subscribe", function (chnl, count) {
if (chnl === channel2) { if (chnl === channel2) {
assert.equal(2, count) assert.equal(2, count);
return done(); return done();
} }
}); });
@ -166,9 +167,9 @@ describe("publish/subscribe", function () {
}); });
describe('unsubscribe', function () { describe('unsubscribe', function () {
it('fires an unsubscribe event', function () { it('fires an unsubscribe event', function (done) {
sub.on("subscribe", function (chnl, count) { sub.on("subscribe", function (chnl, count) {
sub.unsubscribe(channel) sub.unsubscribe(channel);
}); });
sub.subscribe(channel); sub.subscribe(channel);
@ -182,7 +183,7 @@ describe("publish/subscribe", function () {
it('puts client back into write mode', function (done) { it('puts client back into write mode', function (done) {
sub.on("subscribe", function (chnl, count) { sub.on("subscribe", function (chnl, count) {
sub.unsubscribe(channel) sub.unsubscribe(channel);
}); });
sub.subscribe(channel); sub.subscribe(channel);
@ -190,10 +191,10 @@ describe("publish/subscribe", function () {
sub.on("unsubscribe", function (chnl, count) { sub.on("unsubscribe", function (chnl, count) {
pub.incr("foo", helper.isNumber(1, done)); pub.incr("foo", helper.isNumber(1, done));
}); });
}) });
it('does not complain when unsubscribe is called and there are no subscriptions', function () { it('does not complain when unsubscribe is called and there are no subscriptions', function () {
sub.unsubscribe() sub.unsubscribe();
}); });
it('executes callback when unsubscribe is called and there are no subscriptions', function (done) { it('executes callback when unsubscribe is called and there are no subscriptions', function (done) {
@ -216,15 +217,15 @@ describe("publish/subscribe", function () {
assert.strictEqual(channel, '/foo'); assert.strictEqual(channel, '/foo');
assert.strictEqual(message, 'hello world'); assert.strictEqual(message, 'hello world');
return done(); return done();
}) });
pub.publish('/foo', 'hello world'); pub.publish('/foo', 'hello world');
}); });
}); });
describe('punsubscribe', function () { describe('punsubscribe', function () {
it('does not complain when punsubscribe is called and there are no subscriptions', function () { it('does not complain when punsubscribe is called and there are no subscriptions', function () {
sub.punsubscribe() sub.punsubscribe();
}) });
it('executes callback when punsubscribe is called and there are no subscriptions', function (done) { it('executes callback when punsubscribe is called and there are no subscriptions', function (done) {
// test hangs on older versions of redis, so skip // test hangs on older versions of redis, so skip

2
test/queue.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert"); var assert = require("assert");
var Queue = require('../lib/queue'); var Queue = require('../lib/queue');

Loading…
Cancel
Save