1
0
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:
Salakar
2020-02-09 15:44:52 +00:00
parent 43bc8df159
commit da31ade348
4 changed files with 14 additions and 22 deletions

View File

@@ -556,12 +556,8 @@ RedisClient.prototype.connection_gone = function (why, error) {
if (this.retry_delay instanceof Error) { if (this.retry_delay instanceof Error) {
error = this.retry_delay; error = this.retry_delay;
} }
var errorMessage = 'Redis connection in broken state: ';
if (this.retry_totaltime >= this.connect_timeout) { var errorMessage = 'Redis connection in broken state: retry aborted.';
errorMessage += 'connection timeout exceeded.';
} else {
errorMessage += 'maximum connection attempts exceeded.';
}
this.flush_and_error({ this.flush_and_error({
message: errorMessage, message: errorMessage,
@@ -581,13 +577,7 @@ RedisClient.prototype.connection_gone = function (why, error) {
} }
if (this.retry_totaltime >= this.connect_timeout) { if (this.retry_totaltime >= this.connect_timeout) {
var message = 'Redis connection in broken state: '; var message = 'Redis connection in broken state: connection timeout exceeded.';
if (this.retry_totaltime >= this.connect_timeout) {
message += 'connection timeout exceeded.';
} else {
message += 'maximum connection attempts exceeded.';
}
this.flush_and_error({ this.flush_and_error({
message: message, message: message,
code: 'CONNECTION_BROKEN', code: 'CONNECTION_BROKEN',
@@ -864,11 +854,9 @@ RedisClient.prototype.internal_send_command = function (command_obj) {
if (command_obj.args && command_obj.args.length) { if (command_obj.args && command_obj.args.length) {
undefinedArgError.args = command_obj.args; undefinedArgError.args = command_obj.args;
} }
if (command_obj.callback) { // there is always a callback in this scenario
command_obj.callback(undefinedArgError); command_obj.callback(undefinedArgError);
return false; return false;
}
throw undefinedArgError;
} else { } else {
// Seems like numbers are converted fast using string concatenation // Seems like numbers are converted fast using string concatenation
args_copy[i] = '' + args[i]; args_copy[i] = '' + args[i];

View File

@@ -150,6 +150,10 @@ describe("The 'set' method", function () {
client.get('foo', helper.isNull(done)); 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) { it('emit an error with only the key set', function (done) {
client.on('error', function (err) { client.on('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'set' command"); assert.equal(err.message, "ERR wrong number of arguments for 'set' command");

View File

@@ -239,7 +239,7 @@ describe('connection tests', function () {
retryStrategy: function (options) { retryStrategy: function (options) {
if (options.totalRetryTime > 150) { if (options.totalRetryTime > 150) {
client.set('foo', 'bar', function (err, res) { 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'); assert.strictEqual(err.origin.message, 'Connection timeout');
done(); done();
}); });
@@ -257,7 +257,7 @@ describe('connection tests', function () {
retry_strategy: function (options) { retry_strategy: function (options) {
if (options.total_retry_time > 150) { if (options.total_retry_time > 150) {
client.set('foo', 'bar', function (err, res) { 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.code, 'CONNECTION_BROKEN');
assert.strictEqual(err.origin.code, 'ECONNREFUSED'); assert.strictEqual(err.origin.code, 'ECONNREFUSED');
done(); done();
@@ -287,7 +287,7 @@ describe('connection tests', function () {
}, 50); }, 50);
client.on('error', function (err) { client.on('error', function (err) {
if (err instanceof redis.AbortError) { 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'); assert.strictEqual(err.code, 'CONNECTION_BROKEN');
unhookIntercept(); unhookIntercept();
redis.debugMode = false; redis.debugMode = false;

View File

@@ -234,7 +234,7 @@ describe("The 'multi' method", function () {
}); });
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec(function (err, res) { 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.length, 2);
assert.strictEqual(err.errors[0].args.length, 2); assert.strictEqual(err.errors[0].args.length, 2);
}); });