Skip to content

Commit da31ade

Browse files
committed
tests: improve coverage & fix unreachable code branches
1 parent 43bc8df commit da31ade

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

index.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,8 @@ RedisClient.prototype.connection_gone = function (why, error) {
556556
if (this.retry_delay instanceof Error) {
557557
error = this.retry_delay;
558558
}
559-
var errorMessage = 'Redis connection in broken state: ';
560-
if (this.retry_totaltime >= this.connect_timeout) {
561-
errorMessage += 'connection timeout exceeded.';
562-
} else {
563-
errorMessage += 'maximum connection attempts exceeded.';
564-
}
559+
560+
var errorMessage = 'Redis connection in broken state: retry aborted.';
565561

566562
this.flush_and_error({
567563
message: errorMessage,
@@ -581,13 +577,7 @@ RedisClient.prototype.connection_gone = function (why, error) {
581577
}
582578

583579
if (this.retry_totaltime >= this.connect_timeout) {
584-
var message = 'Redis connection in broken state: ';
585-
if (this.retry_totaltime >= this.connect_timeout) {
586-
message += 'connection timeout exceeded.';
587-
} else {
588-
message += 'maximum connection attempts exceeded.';
589-
}
590-
580+
var message = 'Redis connection in broken state: connection timeout exceeded.';
591581
this.flush_and_error({
592582
message: message,
593583
code: 'CONNECTION_BROKEN',
@@ -864,11 +854,9 @@ RedisClient.prototype.internal_send_command = function (command_obj) {
864854
if (command_obj.args && command_obj.args.length) {
865855
undefinedArgError.args = command_obj.args;
866856
}
867-
if (command_obj.callback) {
868-
command_obj.callback(undefinedArgError);
869-
return false;
870-
}
871-
throw undefinedArgError;
857+
// there is always a callback in this scenario
858+
command_obj.callback(undefinedArgError);
859+
return false;
872860
} else {
873861
// Seems like numbers are converted fast using string concatenation
874862
args_copy[i] = '' + args[i];

test/commands/set.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ describe("The 'set' method", function () {
150150
client.get('foo', helper.isNull(done));
151151
});
152152

153+
it('calls callback with error if null value is passed', function (done) {
154+
client.set('foo', null, helper.isError(done));
155+
});
156+
153157
it('emit an error with only the key set', function (done) {
154158
client.on('error', function (err) {
155159
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");

test/connection.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ describe('connection tests', function () {
239239
retryStrategy: function (options) {
240240
if (options.totalRetryTime > 150) {
241241
client.set('foo', 'bar', function (err, res) {
242-
assert.strictEqual(err.message, 'Redis connection in broken state: maximum connection attempts exceeded.');
242+
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
243243
assert.strictEqual(err.origin.message, 'Connection timeout');
244244
done();
245245
});
@@ -257,7 +257,7 @@ describe('connection tests', function () {
257257
retry_strategy: function (options) {
258258
if (options.total_retry_time > 150) {
259259
client.set('foo', 'bar', function (err, res) {
260-
assert.strictEqual(err.message, 'Redis connection in broken state: maximum connection attempts exceeded.');
260+
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
261261
assert.strictEqual(err.code, 'CONNECTION_BROKEN');
262262
assert.strictEqual(err.origin.code, 'ECONNREFUSED');
263263
done();
@@ -287,7 +287,7 @@ describe('connection tests', function () {
287287
}, 50);
288288
client.on('error', function (err) {
289289
if (err instanceof redis.AbortError) {
290-
assert.strictEqual(err.message, 'Redis connection in broken state: maximum connection attempts exceeded.');
290+
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
291291
assert.strictEqual(err.code, 'CONNECTION_BROKEN');
292292
unhookIntercept();
293293
redis.debugMode = false;

test/multi.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe("The 'multi' method", function () {
234234
});
235235

236236
client.multi([['set', 'foo', 'bar'], ['get', 'foo']]).exec(function (err, res) {
237-
assert(/Redis connection in broken state: maximum connection attempts exceeded/.test(err.message));
237+
assert(/Redis connection in broken state: retry aborted/.test(err.message));
238238
assert.strictEqual(err.errors.length, 2);
239239
assert.strictEqual(err.errors[0].args.length, 2);
240240
});

0 commit comments

Comments
 (0)