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
Erin Spiceland 3aaef47756 Fix bug in mocha tests Redis shutdown which expected exit code to eq 0.
Move a miscategorized select test into the correct describe.
2015-08-14 21:31:10 -07:00

43 lines
1.6 KiB
JavaScript

var cp = require('child_process');
var config = require('./config');
var path = require('path');
var tcpPortUsed = require('tcp-port-used');
module.exports = {
start: function (done) {
// spawn redis with our testing configuration.
var confFile = 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);
}
};