From 0c143a7299c5a875e599afb5e9bf4f0fe971806f Mon Sep 17 00:00:00 2001 From: Jeff Barczewski Date: Tue, 26 Mar 2013 10:26:12 -0500 Subject: [PATCH] failing tests for empty unsub and punsub When unsubscribe or punsubscribe is called and there is nothing to unsubscribe from, the reply[1] argument is a null which causes a TypeError Cannot call method 'toString' of null ``` TypeError: Cannot call method 'toString' of null at RedisClient.return_reply (/Users/barczewskij/projects/node_redis/index.js:633:65) at ReplyParser.RedisClient.init_parser (/Users/barczewskij/projects/node_redis/index.js:266:14) at ReplyParser.EventEmitter.emit (events.js:96:17) at ReplyParser.send_reply (/Users/barczewskij/projects/node_redis/lib/parser/javascript.js:300:10) at ReplyParser.execute (/Users/barczewskij/projects/node_redis/lib/parser/javascript.js:211:22) at RedisClient.on_data (/Users/barczewskij/projects/node_redis/index.js:483:27) at Socket. (/Users/barczewskij/projects/node_redis/index.js:82:14) at Socket.EventEmitter.emit (events.js:96:17) at TCP.onread (net.js:396:14) ``` --- test.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index 4b26dca9c9..08fea7f5f6 100644 --- a/test.js +++ b/test.js @@ -614,7 +614,7 @@ tests.detect_buffers = function () { assert.strictEqual("", reply[0].inspect(), name); assert.strictEqual("", reply[1].inspect(), name); }); - + // array of strings with undefined values (repro #344) detect_client.hmget("hash key 2", "key 3", "key 4", function(err, reply) { assert.strictEqual(null, err, name); @@ -864,6 +864,44 @@ tests.SUBSCRIBE = function () { }); }; +tests.UNSUB_EMPTY = function () { + // test situation where unsubscribe reply[1] is null + var name = "UNSUB_EMPTY"; + client3.unsubscribe(); // unsubscribe from all so can test null + client3.unsubscribe(); // reply[1] will be null + next(name); +}; + +tests.PUNSUB_EMPTY = function () { + // test situation where punsubscribe reply[1] is null + var name = "PUNSUB_EMPTY"; + client3.punsubscribe(); // punsubscribe from all so can test null + client3.punsubscribe(); // reply[1] will be null + next(name); +}; + +tests.UNSUB_EMPTY_CB = function () { + // test situation where unsubscribe reply[1] is null + var name = "UNSUB_EMPTY_CB"; + client3.unsubscribe(); // unsubscribe from all so can test null + client3.unsubscribe(function (err, results) { + // reply[1] will be null + assert.strictEqual(null, err, "unexpected error: " + err); + next(name); + }); +}; + +tests.PUNSUB_EMPTY_CB = function () { + // test situation where punsubscribe reply[1] is null + var name = "PUNSUB_EMPTY_CB"; + client3.punsubscribe(); // punsubscribe from all so can test null + client3.punsubscribe(function (err, results) { + // reply[1] will be null + assert.strictEqual(null, err, "unexpected error: " + err); + next(name); + }); +}; + tests.SUB_UNSUB_SUB = function () { var name = "SUB_UNSUB_SUB"; client3.subscribe('chan3');