1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

prep for getting tests to work on appveyor

This commit is contained in:
Benjamin Coe
2015-09-11 23:23:34 -07:00
parent 06121a65c4
commit b4da975785
4 changed files with 30 additions and 8 deletions

View File

@@ -21,7 +21,7 @@
"jshint": "^2.8.0", "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.2.2",
"tcp-port-used": "^0.1.2", "tcp-port-used": "^0.1.2",
"uuid": "^2.0.1" "uuid": "^2.0.1"
}, },

View File

@@ -24,6 +24,8 @@ describe("client authentication", function () {
}); });
it("allows auth to be provided with 'auth' method", function (done) { it("allows auth to be provided with 'auth' method", function (done) {
abortOnSpawnFailure(done);
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
client.auth(auth, function (err, res) { client.auth(auth, function (err, res) {
assert.strictEqual(null, err); assert.strictEqual(null, err);
@@ -33,6 +35,8 @@ describe("client authentication", function () {
}); });
it("raises error when auth is bad", function (done) { it("raises error when auth is bad", function (done) {
abortOnSpawnFailure(done);
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
client.once('error', function (error) { client.once('error', function (error) {
@@ -45,6 +49,8 @@ describe("client authentication", function () {
if (ip === 'IPv4') { if (ip === 'IPv4') {
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) {
abortOnSpawnFailure(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();
@@ -53,6 +59,8 @@ describe("client authentication", function () {
} }
it('allows auth to be provided as config option for client', function (done) { it('allows auth to be provided as config option for client', function (done) {
abortOnSpawnFailure(done);
var args = config.configureClient(parser, ip, { var args = config.configureClient(parser, ip, {
auth_pass: auth auth_pass: auth
}); });
@@ -63,6 +71,8 @@ describe("client authentication", function () {
}); });
it('reconnects with appropriate authentication', function (done) { it('reconnects with appropriate authentication', function (done) {
abortOnSpawnFailure(done);
var readyCount = 0; var readyCount = 0;
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
client.auth(auth); client.auth(auth);
@@ -83,4 +93,13 @@ describe("client authentication", function () {
helper.startRedis('./conf/redis.conf', done); helper.startRedis('./conf/redis.conf', done);
}); });
}); });
// if we fail to spawn Redis (spawning Redis directly is
// not possible in some CI environments) skip the auth tests.
function abortOnSpawnFailure (done) {
if (helper.redisProcess().spawnFailed()) {
console.warn('skipped authentication test')
return done();
}
}
}); });

View File

@@ -28,6 +28,9 @@ if (!process.env.REDIS_TESTS_STARTED) {
} }
module.exports = { module.exports = {
redisProcess: function () {
return rp;
},
stopRedis: function (done) { stopRedis: function (done) {
rp.stop(done); rp.stop(done);
}, },

View File

@@ -5,6 +5,7 @@ var cp = require('child_process');
var config = require('./config'); var config = require('./config');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var spawnFailed = false;
var tcpPortUsed = require('tcp-port-used'); var tcpPortUsed = require('tcp-port-used');
// wait for redis to be listening in // wait for redis to be listening in
@@ -36,13 +37,8 @@ module.exports = {
// capture a failure booting redis, and give // capture a failure booting redis, and give
// the user running the test some directions. // the user running the test some directions.
rp.once("exit", function (code) { rp.once("exit", function (code) {
if (code !== 0) { if (code !== 0) spawnFailed = true;
console.error('failed to starting redis with exit code "' + code + '" ' + })
'stop any other redis processes currently running (' +
'hint: lsof -i :6379)');
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.
@@ -50,7 +46,11 @@ module.exports = {
// return an object that can be used in // return an object that can be used in
// an after() block to shutdown redis. // an after() block to shutdown redis.
return done(null, { return done(null, {
spawnFailed: function () {
return spawnFailed;
},
stop: function (done) { stop: function (done) {
if (spawnFailed) return done();
rp.once("exit", function (code) { rp.once("exit", function (code) {
var error = null; var error = null;
if (code !== null && code !== 0) { if (code !== null && code !== 0) {