You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
tests: improve coverage & fix unreachable code branches
This commit is contained in:
24
index.js
24
index.js
@@ -556,12 +556,8 @@ RedisClient.prototype.connection_gone = function (why, error) {
|
||||
if (this.retry_delay instanceof Error) {
|
||||
error = this.retry_delay;
|
||||
}
|
||||
var errorMessage = 'Redis connection in broken state: ';
|
||||
if (this.retry_totaltime >= this.connect_timeout) {
|
||||
errorMessage += 'connection timeout exceeded.';
|
||||
} else {
|
||||
errorMessage += 'maximum connection attempts exceeded.';
|
||||
}
|
||||
|
||||
var errorMessage = 'Redis connection in broken state: retry aborted.';
|
||||
|
||||
this.flush_and_error({
|
||||
message: errorMessage,
|
||||
@@ -581,13 +577,7 @@ RedisClient.prototype.connection_gone = function (why, error) {
|
||||
}
|
||||
|
||||
if (this.retry_totaltime >= this.connect_timeout) {
|
||||
var message = 'Redis connection in broken state: ';
|
||||
if (this.retry_totaltime >= this.connect_timeout) {
|
||||
message += 'connection timeout exceeded.';
|
||||
} else {
|
||||
message += 'maximum connection attempts exceeded.';
|
||||
}
|
||||
|
||||
var message = 'Redis connection in broken state: connection timeout exceeded.';
|
||||
this.flush_and_error({
|
||||
message: message,
|
||||
code: 'CONNECTION_BROKEN',
|
||||
@@ -864,11 +854,9 @@ RedisClient.prototype.internal_send_command = function (command_obj) {
|
||||
if (command_obj.args && command_obj.args.length) {
|
||||
undefinedArgError.args = command_obj.args;
|
||||
}
|
||||
if (command_obj.callback) {
|
||||
command_obj.callback(undefinedArgError);
|
||||
return false;
|
||||
}
|
||||
throw undefinedArgError;
|
||||
// there is always a callback in this scenario
|
||||
command_obj.callback(undefinedArgError);
|
||||
return false;
|
||||
} else {
|
||||
// Seems like numbers are converted fast using string concatenation
|
||||
args_copy[i] = '' + args[i];
|
||||
|
@@ -150,6 +150,10 @@ describe("The 'set' method", function () {
|
||||
client.get('foo', helper.isNull(done));
|
||||
});
|
||||
|
||||
it('calls callback with error if null value is passed', function (done) {
|
||||
client.set('foo', null, helper.isError(done));
|
||||
});
|
||||
|
||||
it('emit an error with only the key set', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||
|
@@ -239,7 +239,7 @@ describe('connection tests', function () {
|
||||
retryStrategy: function (options) {
|
||||
if (options.totalRetryTime > 150) {
|
||||
client.set('foo', 'bar', function (err, res) {
|
||||
assert.strictEqual(err.message, 'Redis connection in broken state: maximum connection attempts exceeded.');
|
||||
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
|
||||
assert.strictEqual(err.origin.message, 'Connection timeout');
|
||||
done();
|
||||
});
|
||||
@@ -257,7 +257,7 @@ describe('connection tests', function () {
|
||||
retry_strategy: function (options) {
|
||||
if (options.total_retry_time > 150) {
|
||||
client.set('foo', 'bar', function (err, res) {
|
||||
assert.strictEqual(err.message, 'Redis connection in broken state: maximum connection attempts exceeded.');
|
||||
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
|
||||
assert.strictEqual(err.code, 'CONNECTION_BROKEN');
|
||||
assert.strictEqual(err.origin.code, 'ECONNREFUSED');
|
||||
done();
|
||||
@@ -287,7 +287,7 @@ describe('connection tests', function () {
|
||||
}, 50);
|
||||
client.on('error', function (err) {
|
||||
if (err instanceof redis.AbortError) {
|
||||
assert.strictEqual(err.message, 'Redis connection in broken state: maximum connection attempts exceeded.');
|
||||
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
|
||||
assert.strictEqual(err.code, 'CONNECTION_BROKEN');
|
||||
unhookIntercept();
|
||||
redis.debugMode = false;
|
||||
|
@@ -234,7 +234,7 @@ describe("The 'multi' method", function () {
|
||||
});
|
||||
|
||||
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec(function (err, res) {
|
||||
assert(/Redis connection in broken state: maximum connection attempts exceeded/.test(err.message));
|
||||
assert(/Redis connection in broken state: retry aborted/.test(err.message));
|
||||
assert.strictEqual(err.errors.length, 2);
|
||||
assert.strictEqual(err.errors[0].args.length, 2);
|
||||
});
|
||||
|
Reference in New Issue
Block a user