Browse Source

Add jshint and fix errors accordingly (including broken tests)

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

1
.gitignore

@ -2,3 +2,4 @@ node_modules
.tern-port
.nyc_output
coverage
npm-debug.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
}
}
}

5
benches/re_sub_test.js

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

2
benches/stress/pubsub/pub.js

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

3
benches/stress/pubsub/server.js

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

2
benches/stress/rpushblpop/pub.js

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

3
benches/stress/rpushblpop/server.js

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

68
benches/stress/speed/speed.js

@ -16,6 +16,40 @@ var codec = {
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';
for (var i = 0; i < 12; ++i) s += s;
@ -50,37 +84,3 @@ obj = {
rand: []
};
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 port = 6479;
var client = redis.createClient(6479, 'localhost');
function iter() {

56
diff_multi_bench_output.js

@ -2,9 +2,9 @@
'use strict';
var colors = require('colors'),
fs = require('fs'),
_ = require('underscore'),
/* jshint -W079: Ignore redefinitions (before & after) */
var fs = require('fs'),
metrics = require('metrics'),
// `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();
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) {
var a = after_lines[i];
if (!a || !b || !b.trim() || !a.trim()) {
@ -60,33 +82,11 @@ before_lines.forEach(function(b, i) {
pct = humanize_diff(pct, '%');
console.log(
// name of test
command_name(a_words) === command_name(b_words)
? command_name(a_words) + ':'
: '404:',
command_name(a_words) === command_name(b_words) ?
command_name(a_words) + ':' :
'404:',
// results of test
ops.join(' -> '), 'ops/sec (∆', delta, pct, ')');
});
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 () {
console.log("Taking snapshot.");
var snap = profiler.takeSnapshot();
profiler.takeSnapshot();
}, 5000);

52
index.js

@ -1,7 +1,5 @@
'use strict';
/*global Buffer require exports console setTimeout */
var net = require("net"),
URL = require("url"),
util = require("util"),
@ -616,7 +614,7 @@ RedisClient.prototype.return_reply = function (reply) {
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");
}
else {
@ -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 cnxOptions = {
path: path
@ -1224,6 +1198,30 @@ var createClient_tcp = function (port_arg, host_arg, options) {
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) {
if (err) {
console.log("Error: " + err);

4
package.json

@ -11,13 +11,15 @@
"main": "./index.js",
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000"
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000",
"jshint": "./node_modules/.bin/jshint *.js **/*.js **/**/*.js --exclude=node_modules/**/*"
},
"devDependencies": {
"async": "^1.3.0",
"colors": "~0.6.0-1",
"coveralls": "^2.11.2",
"hiredis": "^0.4.1",
"jshint": "^2.8.0",
"metrics": ">=0.1.5",
"mocha": "^2.2.5",
"nyc": "^3.0.0",

5
test/auth.spec.js

@ -1,7 +1,8 @@
'use strict';
var assert = require("assert");
var config = require("./lib/config");
var helper = require('./helper')
var path = require('path');
var helper = require('./helper');
var redis = config.redis;
describe("client authentication", function () {

2
test/commands/blpop.spec.js

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

2
test/commands/client.spec.js

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

3
test/commands/dbsize.spec.js

@ -1,4 +1,5 @@
var async = require('async');
'use strict';
var assert = require('assert');
var config = require("../lib/config");
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 helper = require("../helper");
var redis = config.redis;

2
test/commands/eval.spec.js

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

3
test/commands/exits.spec.js

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

3
test/commands/expire.spec.js

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

2
test/commands/flushdb.spec.js

@ -1,3 +1,5 @@
'use strict';
var async = require('async');
var assert = require('assert');
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 config = require("../lib/config");
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 config = require("../lib/config");
var helper = require('../helper');

2
test/commands/hgetall.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
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 helper = require("../helper");
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 helper = require("../helper");
var redis = config.redis;

2
test/commands/hmget.spec.js

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

10
test/commands/hmset.spec.js

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

2
test/commands/hset.spec.js

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

4
test/commands/incr.spec.js

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

2
test/commands/keys.spec.js

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

2
test/commands/mget.spec.js

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

3
test/commands/mset.spec.js

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

3
test/commands/msetnx.spec.js

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

9
test/commands/multi.spec.js

@ -1,4 +1,5 @@
var async = require('async');
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var helper = require('../helper');
@ -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) {
var name = "MULTI_1", multi1, multi2;
var multi1, multi2;
// Provoke an error at queue time
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,
// perhaps @mranney can clarify?
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.set("foo2", 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.
multi2 = client.multi();
var multi2 = client.multi();
multi2.incr("multibar_8", helper.isNumber(multibar_expected));
multi2.incr("multifoo_8", helper.isNumber(multifoo_expected));
multi2.exec(function (err, replies) {

2
test/commands/randomkey.test.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
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 helper = require("../helper");
var redis = config.redis;

3
test/commands/renamenx.spec.js

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

2
test/commands/sadd.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
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 helper = require("../helper");
var redis = config.redis;

2
test/commands/script.spec.js

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

2
test/commands/sdiff.spec.js

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

2
test/commands/sdiffstore.spec.js

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

3
test/commands/select.spec.js

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

3
test/commands/set.spec.js

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

2
test/commands/setex.spec.js

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

3
test/commands/setnx.spec.js

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

2
test/commands/sinter.spec.js

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

2
test/commands/sinterstore.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
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 helper = require("../helper");
var redis = config.redis;

2
test/commands/slowlog.spec.js

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

2
test/commands/smembers.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
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 helper = require("../helper");
var redis = config.redis;

2
test/commands/sort.spec.js

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

2
test/commands/spop.spec.js

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

2
test/commands/srem.spec.js

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

2
test/commands/sunion.spec.js

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

2
test/commands/sunionstore.spec.js

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

2
test/commands/ttl.spec.js

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

3
test/commands/type.spec.js

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

22
test/commands/watch.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
@ -33,7 +35,7 @@ describe("The 'watch' method", function () {
it('does not execute transaction if watched key was modified prior to execution', function (done) {
client.watch(watched);
client.incr(watched);
multi = client.multi();
var multi = client.multi();
multi.incr(watched);
multi.exec(helper.isNull(done));
})
@ -45,17 +47,15 @@ describe("The 'watch' method", function () {
client.watch(watched);
client.incr(watched);
var multi = client.multi()
.incr(watched)
.exec(function (err, replies) {
assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null.");
client.multi().incr(watched).exec(function (err, replies) {
assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null.");
client.get("unwatched", function (err, reply) {
assert.equal(reply, 200, "Expected 200, got " + reply);
return done(err)
});
});
})
client.get("unwatched", function (err, reply) {
assert.equal(reply, 200, "Expected 200, got " + reply);
return done(err);
});
});
});
});
});
});

18
test/helper.js

@ -1,9 +1,18 @@
'use strict';
var assert = require("assert");
var path = require('path');
var config = require("./lib/config");
var RedisProcess = require("./lib/redis-process");
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
// include this helper file!
if (!process.env.REDIS_TESTS_STARTED) {
@ -108,11 +117,4 @@ module.exports = {
process.removeListener('uncaughtException', mochaListener);
return mochaListener;
}
}
function startRedis (conf, done) {
RedisProcess.start(function (err, _rp) {
rp = _rp;
return done(err);
}, path.resolve(__dirname, conf));
}
};

2
test/lib/config.js

@ -1,3 +1,5 @@
'use strict';
// helpers for configuring a redis client in
// its various modes, ipV6, ipV4, socket.
var redis = require('../../index');

46
test/lib/redis-process.js

@ -1,3 +1,5 @@
'use strict';
// helper to start and stop the redis process.
var cp = require('child_process');
var config = require('./config');
@ -5,6 +7,26 @@ var fs = require('fs');
var path = require('path');
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 = {
start: function (done, conf) {
// spawn redis with our testing configuration.
@ -18,9 +40,9 @@ module.exports = {
console.error('failed to starting redis with exit code "' + code + '" ' +
'stop any other redis processes currently running (' +
'hint: lsof -i :6379)');
process.exit(code)
process.exit(code);
}
})
});
// wait for redis to become available, by
// checking the port we bind on.
@ -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);
}

10
test/node_redis.spec.js

@ -1,3 +1,5 @@
'use strict';
var async = require("async");
var assert = require("assert");
var config = require("./lib/config");
@ -249,7 +251,7 @@ describe("The node_redis client", function () {
try {
domain = require('domain').create();
} 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();
}
@ -257,7 +259,7 @@ describe("The node_redis client", function () {
domain.run(function () {
client.set('domain', 'value', function (err, res) {
assert.ok(process.domain);
var notFound = res.not.existing.thing; // ohhh nooooo
throw new Error('ohhhh noooo');
});
});
@ -316,7 +318,7 @@ describe("The node_redis client", function () {
});
client2.on("message", function (channel, data) {
if (channel == name) {
if (channel === name) {
assert.equal(data, "some message");
throw Error('forced exception');
}
@ -736,7 +738,7 @@ describe("The node_redis client", function () {
});
assert.throws(function () {
cli.set('foo', 'bar');
client.set('foo', 'bar');
});
assert.doesNotThrow(function () {

2
test/parser/javascript.spec.js

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

11
test/pubsub.spec.js

@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var config = require("./lib/config");
var helper = require("./helper");
@ -10,10 +12,9 @@ describe("publish/subscribe", function () {
describe("using " + parser + " and " + ip, function () {
var pub = null;
var sub = null;
var channel = "test channel"
var channel2 = "test channel 2"
var message = "test message"
var hash = "test hash";
var channel = "test channel";
var channel2 = "test channel 2";
var message = "test message";
beforeEach(function (done) {
var pubConnected;
@ -166,7 +167,7 @@ describe("publish/subscribe", function () {
});
describe('unsubscribe', function () {
it('fires an unsubscribe event', function () {
it('fires an unsubscribe event', function (done) {
sub.on("subscribe", function (chnl, count) {
sub.unsubscribe(channel)
});

2
test/queue.spec.js

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

Loading…
Cancel
Save