From 0b51924aa75c598a6883dc4b8b3c95e1553c3725 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 20 Sep 2010 12:29:35 -0700 Subject: [PATCH] ensure client emits connect and end events --- index.js | 2 +- test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5c1b21881b..afcf58ae25 100644 --- a/index.js +++ b/index.js @@ -390,7 +390,7 @@ RedisClient.prototype.connection_gone = function () { console.warn("Redis connection is gone."); } self.connected = false; - self.emit("close"); + self.emit("end"); self.command_queue.forEach(function (args) { if (typeof args[2] === "function") { args[2]("Server connection closed"); diff --git a/test.js b/test.js index 0f0a372e5c..d8402844b9 100644 --- a/test.js +++ b/test.js @@ -374,11 +374,18 @@ function run_next_test() { } } +var connected = false; +var ended = false; client.on("connect", function () { + connected = true; console.log(); run_next_test(); }); +client.on('end', function() { + ended = true; +}); + client.on("error", function (err) { console.log("Redis clent connection failed."); }); @@ -390,3 +397,8 @@ client.on("reconnecting", function (msg) { process.on('uncaughtException', function (err) { console.log("Uncaught exception: " + err.stack); }); + +process.on('exit', function(code) { + assert.equal(true, connected); + assert.equal(true, ended); +}); \ No newline at end of file