You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fixed up some tests, changed how redis spawns
This commit is contained in:
@@ -4,8 +4,5 @@ node_js:
|
|||||||
- "0.10"
|
- "0.10"
|
||||||
- "0.12"
|
- "0.12"
|
||||||
- "iojs"
|
- "iojs"
|
||||||
before_install:
|
script: npm run mocha
|
||||||
- 'printf ''bind ::1 127.0.0.1\nunixsocket /tmp/redis.sock\ndaemonize yes\nunixsocketperm 777'' >> /tmp/redis.conf'
|
|
||||||
before_script:
|
|
||||||
- sudo redis-server /tmp/redis.conf
|
|
||||||
after_success: npm run coverage
|
after_success: npm run coverage
|
||||||
|
@@ -11,7 +11,8 @@
|
|||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"test": "nyc ./test/run.sh"
|
"test": "nyc ./test/run.sh",
|
||||||
|
"mocha": "nyc mocha ./test/mocha/*.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^1.3.0",
|
"async": "^1.3.0",
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
"metrics": ">=0.1.5",
|
"metrics": ">=0.1.5",
|
||||||
"mocha": "^2.2.5",
|
"mocha": "^2.2.5",
|
||||||
"nyc": "^3.0.0",
|
"nyc": "^3.0.0",
|
||||||
|
"tcp-port-used": "^0.1.2",
|
||||||
"underscore": "~1.4.4"
|
"underscore": "~1.4.4"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@@ -1,28 +0,0 @@
|
|||||||
var pm = require('./test/lib/redis-process');
|
|
||||||
var cp = require('child_process');
|
|
||||||
var testSets = 'test/mocha/**/*.spec.js';
|
|
||||||
var async = require('async');
|
|
||||||
var redis;
|
|
||||||
|
|
||||||
process.on("exit", function () {
|
|
||||||
if (redis) {
|
|
||||||
redis.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async.series([function startRedis(next) {
|
|
||||||
redis = pm.start(function (err) {
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
}, function runMocha(next) {
|
|
||||||
var mocha = cp.spawn('mocha', [testSets], {
|
|
||||||
stdio: "inherit"
|
|
||||||
});
|
|
||||||
mocha.on("exit", function (code) {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}, function stopRedis(next) {
|
|
||||||
redis.stop(next);
|
|
||||||
}], function (err) {
|
|
||||||
// done;
|
|
||||||
});
|
|
@@ -1,5 +1,4 @@
|
|||||||
daemonize yes
|
|
||||||
port 6378
|
port 6378
|
||||||
bind ::1
|
bind ::1 127.0.0.1
|
||||||
unixsocket /tmp/redis.sock
|
unixsocket /tmp/redis.sock
|
||||||
unixsocketperm 755
|
unixsocketperm 755
|
||||||
|
@@ -1,23 +1,40 @@
|
|||||||
var cp = require('child_process');
|
var cp = require('child_process');
|
||||||
|
var config = require('./config');
|
||||||
|
var path = require('path');
|
||||||
|
var tcpPortUsed = require('tcp-port-used');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
start: function (done, isSocket) {
|
start: function (done) {
|
||||||
var confFile = isSocket ? "test/conf/redis-socket.conf" : "test/conf/redis.conf";
|
// spawn redis with our testing configuration.
|
||||||
var redis = cp.spawn("redis-server", [confFile]);
|
var confFile = path.resolve(__dirname, '../conf/redis.conf');
|
||||||
|
var rp = cp.spawn("redis-server", [confFile], {});
|
||||||
|
|
||||||
redis.once('err', done);
|
// wait for redis to become available, by
|
||||||
setTimeout(function (data) {
|
// checking the port we bind on.
|
||||||
redis.removeListener('err', done);
|
var id = setInterval(function () {
|
||||||
done();
|
tcpPortUsed.check(config.PORT, '127.0.0.1')
|
||||||
}, 1000);
|
.then(function (inUse) {
|
||||||
|
if (inUse) {
|
||||||
|
clearInterval(id);
|
||||||
|
|
||||||
return {
|
// return an object that can be used in
|
||||||
stop: function (done) {
|
// an after() block to shutdown redis.
|
||||||
redis.once("exit", function () {
|
return done(null, {
|
||||||
done();
|
stop: function (done) {
|
||||||
});
|
rp.once("exit", function (code) {
|
||||||
redis.kill("SIGINT");
|
var error = null;
|
||||||
}
|
if (code !== 0) error = Error('failed to shutdown redis');
|
||||||
};
|
return done(error);
|
||||||
|
});
|
||||||
|
rp.kill("SIGINT");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
clearInterval(id);
|
||||||
|
return done(err);
|
||||||
|
})
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,11 +1,21 @@
|
|||||||
var nodeAssert = require("../lib/nodeify-assertions");
|
|
||||||
var config = require("../lib/config");
|
|
||||||
var redis = config.redis;
|
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
|
var config = require("../lib/config");
|
||||||
|
var nodeAssert = require("../lib/nodeify-assertions");
|
||||||
|
var redis = config.redis;
|
||||||
|
var RedisProcess = require("../lib/redis-process");
|
||||||
|
|
||||||
describe("A node_redis client", function () {
|
describe("A node_redis client", function () {
|
||||||
function allTests(parser, ip, isSocket) {
|
|
||||||
var args = config.configureClient(parser, ip, isSocket);
|
var rp;
|
||||||
|
before(function (done) {
|
||||||
|
RedisProcess.start(function (err, _rp) {
|
||||||
|
rp = _rp;
|
||||||
|
return done(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
function allTests(parser, ip) {
|
||||||
|
var args = config.configureClient(parser, ip);
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe("using " + parser + " and " + ip, function () {
|
||||||
var client;
|
var client;
|
||||||
@@ -157,9 +167,13 @@ describe("A node_redis client", function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
['javascript', 'hiredis'].forEach(function (parser) {
|
['javascript', 'hiredis'].forEach(function (parser) {
|
||||||
allTests(parser, "/tmp/redis.sock", true);
|
allTests(parser, "/tmp/redis.sock");
|
||||||
['IPv4', 'IPv6'].forEach(function (ip) {
|
['IPv4', 'IPv6'].forEach(function (ip) {
|
||||||
allTests(parser, ip);
|
allTests(parser, ip);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(function (done) {
|
||||||
|
if (rp) rp.stop(done);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
@@ -1,12 +1,28 @@
|
|||||||
var nodeAssert = require("../lib/nodeify-assertions");
|
var async = require('async');
|
||||||
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require("../lib/config");
|
||||||
|
var nodeAssert = require('../lib/nodeify-assertions');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var async = require("async");
|
var RedisProcess = require("../lib/redis-process");
|
||||||
var assert = require("assert");
|
|
||||||
|
|
||||||
describe("The 'select' method", function () {
|
describe("The 'select' method", function () {
|
||||||
function allTests(parser, ip, isSocket) {
|
|
||||||
var args = config.configureClient(parser, ip, isSocket);
|
var rp;
|
||||||
|
before(function (done) {
|
||||||
|
RedisProcess.start(function (err, _rp) {
|
||||||
|
rp = _rp;
|
||||||
|
return done(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
function removeMochaListener () {
|
||||||
|
var mochaListener = process.listeners('uncaughtException').pop();
|
||||||
|
process.removeListener('uncaughtException', mochaListener);
|
||||||
|
return mochaListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
function allTests(parser, ip) {
|
||||||
|
var args = config.configureClient(parser, ip);
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe("using " + parser + " and " + ip, function () {
|
||||||
describe("when not connected", function () {
|
describe("when not connected", function () {
|
||||||
@@ -15,26 +31,19 @@ describe("The 'select' method", function () {
|
|||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(redis.createClient, args);
|
client = redis.createClient.apply(redis.createClient, args);
|
||||||
client.once("error", done);
|
client.once("error", done);
|
||||||
|
|
||||||
client.once("connect", function () {
|
client.once("connect", function () {
|
||||||
client.set("doot", "good calsum", function (err, res) {
|
client.quit();
|
||||||
client.end();
|
});
|
||||||
done();
|
client.on('end', function () {
|
||||||
});
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't even throw an error or call the callback at all WTF", function (done) {
|
it("throws an error if redis is not connected", function (done) {
|
||||||
this.timeout(50);
|
|
||||||
|
|
||||||
client.select(1, function (err, res) {
|
client.select(1, function (err, res) {
|
||||||
nodeAssert.isNotError()(err, res);
|
assert.equal(err.message, 'Redis connection gone from end event.');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
done();
|
|
||||||
}, 45);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -44,10 +53,7 @@ describe("The 'select' method", function () {
|
|||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(redis.createClient, args);
|
client = redis.createClient.apply(redis.createClient, args);
|
||||||
client.once("error", done);
|
client.once("error", done);
|
||||||
|
client.once("connect", function () { done(); });
|
||||||
client.once("connect", function () {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@@ -65,54 +71,37 @@ describe("The 'select' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("and no callback is specified", function () {
|
describe("and no callback is specified", function () {
|
||||||
// select_error_emits_if_no_callback
|
|
||||||
// this is another test that was testing the wrong thing. The old test did indeed emit an error,
|
|
||||||
// but not because of the lacking callback, but because 9999 was an invalid db index.
|
|
||||||
describe("with a valid db index", function () {
|
describe("with a valid db index", function () {
|
||||||
it("works just fine and does not actually emit an error like the old tests assert WTF", function (done) {
|
it("selects the appropriate database", function (done) {
|
||||||
assert.strictEqual(client.selected_db, null, "default db should be null");
|
assert.strictEqual(client.selected_db, null, "default db should be null");
|
||||||
this.timeout(50);
|
|
||||||
client.on("error", function (err) {
|
|
||||||
nodeAssert.isNotError()(err);
|
|
||||||
assert.strictEqual(client.selected_db, 1, "db should be 1 after select");
|
|
||||||
done(new Error("the old tests were crap"));
|
|
||||||
});
|
|
||||||
client.select(1);
|
client.select(1);
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
done();
|
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
|
||||||
}, 45);
|
return done();
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Can't seem to catch the errors thrown here.
|
describe("with an invalid db index", function () {
|
||||||
xdescribe("with an invalid db index", function () {
|
|
||||||
it("emits an error", function (done) {
|
it("emits an error", function (done) {
|
||||||
this.timeout(50);
|
|
||||||
|
|
||||||
assert.strictEqual(client.selected_db, null, "default db should be null");
|
assert.strictEqual(client.selected_db, null, "default db should be null");
|
||||||
client.on("error", function (err) {
|
client.select(9999, function (err) {
|
||||||
console.log('got an error', err);
|
assert.equal(err.message, 'ERR invalid DB index')
|
||||||
done();
|
return done();
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
client.select(9999);
|
|
||||||
} catch (err) {}
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
done(new Error("It was supposed to emit an error."));
|
|
||||||
}, 45);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an error bc a callback is not", function (done) {
|
it("throws an error when callback not provided", function (done) {
|
||||||
|
var mochaListener = removeMochaListener();
|
||||||
assert.strictEqual(client.selected_db, null, "default db should be null");
|
assert.strictEqual(client.selected_db, null, "default db should be null");
|
||||||
try {
|
|
||||||
client.select(9999);
|
process.once('uncaughtException', function (err) {
|
||||||
done(new Error("Was supposed to throw an invalid db index error."));
|
process.on('uncaughtException', mochaListener);
|
||||||
} catch (err) {
|
assert.equal(err.message, 'ERR invalid DB index');
|
||||||
done();
|
return done();
|
||||||
}
|
});
|
||||||
|
|
||||||
|
client.select(9999);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -121,10 +110,13 @@ describe("The 'select' method", function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
['javascript', 'hiredis'].forEach(function (parser) {
|
['javascript', 'hiredis'].forEach(function (parser) {
|
||||||
//allTests(parser, "/tmp/redis.sock", true);
|
allTests(parser, "/tmp/redis.sock");
|
||||||
//['IPv4', 'IPv6'].forEach(function (ip) {
|
['IPv4', 'IPv6'].forEach(function (ip) {
|
||||||
['IPv4'].forEach(function (ip) {
|
|
||||||
allTests(parser, ip);
|
allTests(parser, ip);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(function (done) {
|
||||||
|
if (rp) rp.stop(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user