You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Fix some minor issues and add more tests
Do not mutate the options object and add some more tests
This commit is contained in:
@@ -31,7 +31,7 @@ describe("The 'expire' method", function () {
|
||||
client.EXPIRE(["expiry key", "1"], helper.isNumber(1));
|
||||
setTimeout(function () {
|
||||
client.exists(["expiry key"], helper.isNumber(0, done));
|
||||
}, 3000);
|
||||
}, 1100);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@@ -37,6 +37,12 @@ describe("The 'get' method", function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("reports an error promisified", function () {
|
||||
return client.getAsync(key).then(assert, function (err) {
|
||||
assert(err.message.match(/The connection has already been closed/));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when connected", function () {
|
||||
@@ -76,7 +82,7 @@ describe("The 'get' method", function () {
|
||||
}]);
|
||||
});
|
||||
|
||||
it("should not throw on a get without callback (even if it's not useful", function (done) {
|
||||
it("should not throw on a get without callback (even if it's not useful)", function (done) {
|
||||
client.GET(key);
|
||||
client.on('error', function(err) {
|
||||
throw err;
|
||||
|
@@ -67,6 +67,50 @@ describe("The 'multi' method", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when connection is broken", function () {
|
||||
var client;
|
||||
|
||||
afterEach(function () {
|
||||
client.end();
|
||||
});
|
||||
|
||||
it("return an error even if connection is in broken mode if callback is present", function (done) {
|
||||
client = redis.createClient({
|
||||
host: 'somewhere',
|
||||
port: 6379,
|
||||
max_attempts: 1
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
if (/Redis connection in broken state/.test(err.message)) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec(function (err, res) {
|
||||
assert(/Redis connection in broken state/.test(err.message));
|
||||
assert.strictEqual(err.errors.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not emit an error twice if connection is in broken mode with no callback", function (done) {
|
||||
client = redis.createClient({
|
||||
host: 'somewhere',
|
||||
port: 6379,
|
||||
max_attempts: 1
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
// Results in multiple done calls if test fails
|
||||
if (/Redis connection in broken state/.test(err.message)) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when ready", function () {
|
||||
var client;
|
||||
|
||||
@@ -481,6 +525,18 @@ describe("The 'multi' method", function () {
|
||||
assert(!test);
|
||||
});
|
||||
|
||||
it("do not mutate arguments in the multi constructor", function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [2, 6, 5]);
|
||||
|
||||
var input = [['set', 'foo', 'bar'], ['get', 'foo']];
|
||||
client.multi(input).exec(function (err, res) {
|
||||
assert.strictEqual(input.length, 2);
|
||||
assert.strictEqual(input[0].length, 3);
|
||||
assert.strictEqual(input[1].length, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user