You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
slight refactor from code review
smoke test large list of commands ported more tests to mocha, some slight cleanup in tests move sinon and uuid to dev dependencies finished porting eval tests over to mocha rebased mocha testing branch with master ported client and script tests ported watch tests ported detect_buffers tests ported unref tests ported auth tests over to mocha ported idle and no_delay tests ported hlen, hset continuing marching forward ported hincrby, sinter, sort, pubsub tests. improved logic in redis-process, I was still occasionally having issues where redis failed to exit. switch back to default test command ported del, exists, hlen, keys, randomkey, type cleanup based on what I've learned so far from refactor. we now start and stop redis less often. moved tests to their final resting place finished porting node_redis client tests ported hgetall, mget, msetnx, rename, renamenx, setex, setnx ported hgetall, mget, msetnx, rename, renamenx, setex, setnx ported queue tests to mocha amalgamated some of the helper logic ported sadd, scard, sismember, srem, utf-8
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// helpers for configuring a redis client in
|
||||
// its various modes, ipV6, ipV4, socket.
|
||||
module.exports = (function () {
|
||||
var redis = require('../../index');
|
||||
redis.debug_mode = process.env.DEBUG ? JSON.parse(process.env.DEBUG) : false;
|
||||
@@ -11,18 +13,21 @@ module.exports = (function () {
|
||||
}
|
||||
};
|
||||
|
||||
config.configureClient = function (parser, ip, isSocket) {
|
||||
config.configureClient = function (parser, ip, opts) {
|
||||
var args = [];
|
||||
opts = opts || {};
|
||||
|
||||
if (!isSocket) {
|
||||
if (ip.match(/\.sock/)) {
|
||||
args.push(ip)
|
||||
} else {
|
||||
args.push(config.PORT);
|
||||
args.push(config.HOST[ip]);
|
||||
args.push({ family: ip, parser: parser });
|
||||
} else {
|
||||
args.push(ip);
|
||||
args.push({ parser: parser });
|
||||
opts.family = ip;
|
||||
}
|
||||
|
||||
opts.parser = parser;
|
||||
args.push(opts);
|
||||
|
||||
return args;
|
||||
};
|
||||
|
||||
|
@@ -1,70 +0,0 @@
|
||||
var assert = require('assert');
|
||||
|
||||
module.exports = {
|
||||
isNumber: function (expected) {
|
||||
return function (err, results) {
|
||||
assert.strictEqual(null, err, "expected " + expected + ", got error: " + err);
|
||||
assert.strictEqual(expected, results, expected + " !== " + results);
|
||||
assert.strictEqual(typeof results, "number", "expected a number, got " + typeof results);
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
isString: function (str) {
|
||||
return function (err, results) {
|
||||
assert.strictEqual(null, err, "expected string '" + str + "', got error: " + err);
|
||||
assert.equal(str, results, str + " does not match " + results);
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
isNull: function () {
|
||||
return function (err, results) {
|
||||
assert.strictEqual(null, err, "expected null, got error: " + err);
|
||||
assert.strictEqual(null, results, results + " is not null");
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
isError: function () {
|
||||
return function (err, results) {
|
||||
assert.notEqual(err, null, "err is null, but an error is expected here.");
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
isNotError: function () {
|
||||
return function (err, results) {
|
||||
assert.strictEqual(err, null, "expected success, got an error: " + err);
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
isType: {
|
||||
number: function () {
|
||||
return function (err, results) {
|
||||
assert.strictEqual(null, err, "expected any number, got error: " + err);
|
||||
assert.strictEqual(typeof results, "number", results + " is not a number");
|
||||
return true;
|
||||
};
|
||||
},
|
||||
|
||||
positiveNumber: function () {
|
||||
return function (err, results) {
|
||||
assert.strictEqual(null, err, "expected positive number, got error: " + err);
|
||||
assert.strictEqual(true, (results > 0), results + " is not a positive number");
|
||||
return true;
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
serverVersionAtLeast: function (connection, desired_version) {
|
||||
// Return true if the server version >= desired_version
|
||||
var version = connection.server_info.versions;
|
||||
for (var i = 0; i < 3; i++) {
|
||||
if (version[i] > desired_version[i]) return true;
|
||||
if (version[i] < desired_version[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
@@ -1,42 +1,55 @@
|
||||
// helper to start and stop the redis process.
|
||||
var cp = require('child_process');
|
||||
var config = require('./config');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var tcpPortUsed = require('tcp-port-used');
|
||||
|
||||
module.exports = {
|
||||
start: function (done) {
|
||||
start: function (done, conf) {
|
||||
// spawn redis with our testing configuration.
|
||||
var confFile = path.resolve(__dirname, '../conf/redis.conf');
|
||||
var confFile = conf || path.resolve(__dirname, '../conf/redis.conf');
|
||||
var rp = cp.spawn("redis-server", [confFile], {});
|
||||
|
||||
// wait for redis to become available, by
|
||||
// checking the port we bind on.
|
||||
var id = setInterval(function () {
|
||||
tcpPortUsed.check(config.PORT, '127.0.0.1')
|
||||
.then(function (inUse) {
|
||||
if (inUse) {
|
||||
clearInterval(id);
|
||||
|
||||
// return an object that can be used in
|
||||
// an after() block to shutdown redis.
|
||||
return done(null, {
|
||||
stop: function (done) {
|
||||
rp.once("exit", function (code) {
|
||||
var error = null;
|
||||
if (code !== null && code !== 0) {
|
||||
error = Error('Redis shutdown failed with code ' + code);
|
||||
}
|
||||
return done(error);
|
||||
});
|
||||
rp.kill("SIGINT");
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
clearInterval(id);
|
||||
return done(err);
|
||||
})
|
||||
}, 100);
|
||||
waitForRedis(true, function () {
|
||||
// return an object that can be used in
|
||||
// an after() block to shutdown redis.
|
||||
return done(null, {
|
||||
stop: function (done) {
|
||||
rp.once("exit", function (code) {
|
||||
var error = null;
|
||||
if (code !== null && code !== 0) {
|
||||
error = Error('Redis shutdown failed with code ' + code);
|
||||
}
|
||||
waitForRedis(false, function () {
|
||||
return done(error);
|
||||
})
|
||||
});
|
||||
rp.kill("SIGTERM");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
18
test/lib/unref.js
Normal file
18
test/lib/unref.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// spawned by the unref tests in node_redis.spec.js.
|
||||
// when configured, unref causes the client to exit
|
||||
// as soon as there are no outstanding commands.
|
||||
'use strict';
|
||||
|
||||
var redis = require("../../");
|
||||
//redis.debug_mode = true
|
||||
var HOST = process.argv[2] || '127.0.0.1';
|
||||
var PORT = process.argv[3]
|
||||
var args = PORT ? [PORT, HOST] : [HOST]
|
||||
|
||||
var c = redis.createClient.apply(redis, args);
|
||||
c.unref();
|
||||
c.info(function (err, reply) {
|
||||
if (err) process.exit(-1);
|
||||
if (!reply.length) process.exit(-1);
|
||||
process.stdout.write(reply.length.toString());
|
||||
});
|
Reference in New Issue
Block a user