From 6598da536620f6e3c713cebd00fa6c28e24dd596 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 14 Mar 2016 22:55:01 +0100 Subject: [PATCH] Indicate transmission errors --- index.js | 4 ++-- test/auth.spec.js | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 5ded1abce6..f35dd1b6a5 100644 --- a/index.js +++ b/index.js @@ -233,8 +233,8 @@ RedisClient.prototype.create_stream = function () { self.on_error(err); }); - this.stream.once('close', function () { - self.connection_gone('close', new Error('Stream connection closed')); + this.stream.once('close', function (hadError) { + self.connection_gone('close', new Error('Stream connection closed' + (hadError ? ' because of a transmission error' : ''))); }); this.stream.once('end', function () { diff --git a/test/auth.spec.js b/test/auth.spec.js index f09cef6f98..102bce91f8 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -115,9 +115,7 @@ describe("client authentication", function () { auth_pass: auth }); client = redis.createClient.apply(null, args); - client.on("ready", function () { - return done(); - }); + client.on("ready", done); }); it('allows auth and no_ready_check to be provided as config option for client', function (done) { @@ -128,9 +126,7 @@ describe("client authentication", function () { no_ready_check: true }); client = redis.createClient.apply(null, args); - client.on("ready", function () { - done(); - }); + client.on("ready", done); }); it('allows auth to be provided post-hoc with auth method', function (done) { @@ -139,25 +135,24 @@ describe("client authentication", function () { var args = config.configureClient(parser, ip); client = redis.createClient.apply(null, args); client.auth(auth); - client.on("ready", function () { - return done(); - }); + client.on("ready", done); }); it('reconnects with appropriate authentication', function (done) { if (helper.redisProcess().spawnFailed()) this.skip(); - var readyCount = 0; client = redis.createClient.apply(null, args); client.auth(auth); client.on("ready", function () { - readyCount++; - if (readyCount === 1) { + if (this.times_connected === 1) { client.stream.destroy(); } else { - return done(); + done(); } }); + client.on('reconnecting', function (params) { + assert.strictEqual(params.error.message, 'Stream connection closed'); + }); }); it('should return an error if the password is not of type string and a callback has been provided', function (done) {