1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/test/lib/redis-process.js
Benjamin Coe a0832c3744 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
2015-08-14 21:31:18 -07:00

56 lines
1.9 KiB
JavaScript

// 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, conf) {
// spawn redis with our testing configuration.
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.
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);
}