Skip to content

Commit

Permalink
tests: improve coverage & fix unreachable code branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar committed Feb 9, 2020
1 parent 43bc8df commit da31ade
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
24 changes: 6 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions test/commands/set.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions test/connection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/multi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit da31ade

Please sign in to comment.