From 8bf794fb36f97be1025de7efa93a63decd03524b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 22 Nov 2015 16:56:54 +0100 Subject: [PATCH] Stricten tests by always ending redis with .end(true) if possible --- README.md | 5 ++--- test/auth.spec.js | 4 +++- test/commands/blpop.spec.js | 4 ++-- test/commands/client.spec.js | 4 ++-- test/commands/dbsize.spec.js | 2 +- test/commands/del.spec.js | 2 +- test/commands/eval.spec.js | 2 +- test/commands/exits.spec.js | 2 +- test/commands/expire.spec.js | 2 +- test/commands/flushdb.spec.js | 2 +- test/commands/geoadd.spec.js | 2 +- test/commands/get.spec.js | 2 +- test/commands/getset.spec.js | 2 +- test/commands/hgetall.spec.js | 2 +- test/commands/hincrby.spec.js | 2 +- test/commands/hlen.spec.js | 2 +- test/commands/hmget.spec.js | 2 +- test/commands/hmset.spec.js | 2 +- test/commands/hset.spec.js | 2 +- test/commands/incr.spec.js | 4 ++-- test/commands/keys.spec.js | 2 +- test/commands/mget.spec.js | 2 +- test/commands/mset.spec.js | 2 +- test/commands/msetnx.spec.js | 2 +- test/commands/randomkey.test.js | 2 +- test/commands/rename.spec.js | 2 +- test/commands/renamenx.spec.js | 2 +- test/commands/rpush.spec.js | 2 +- test/commands/sadd.spec.js | 2 +- test/commands/scard.spec.js | 2 +- test/commands/script.spec.js | 2 +- test/commands/sdiff.spec.js | 2 +- test/commands/sdiffstore.spec.js | 2 +- test/commands/select.spec.js | 2 +- test/commands/set.spec.js | 2 +- test/commands/setex.spec.js | 2 +- test/commands/setnx.spec.js | 2 +- test/commands/sinter.spec.js | 2 +- test/commands/sinterstore.spec.js | 2 +- test/commands/sismember.spec.js | 2 +- test/commands/slowlog.spec.js | 2 +- test/commands/smembers.spec.js | 2 +- test/commands/smove.spec.js | 2 +- test/commands/sort.spec.js | 2 +- test/commands/spop.spec.js | 2 +- test/commands/srem.spec.js | 2 +- test/commands/sunion.spec.js | 2 +- test/commands/sunionstore.spec.js | 2 +- test/commands/sync.spec.js | 2 +- test/commands/ttl.spec.js | 2 +- test/commands/type.spec.js | 2 +- test/commands/watch.spec.js | 2 +- test/commands/zadd.spec.js | 2 +- test/commands/zscan.spec.js | 2 +- test/commands/zscore.spec.js | 2 +- test/connection.spec.js | 4 ++-- test/node_redis.spec.js | 35 ++++++++++++++++++------------- 57 files changed, 83 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 279bb0f97d..bd7c8fd480 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ something like this `Error: Ready check failed: ERR operation not permitted`. Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed. If you want to exit cleanly, call `client.quit()` to send the `QUIT` command after you have handled all replies. -If flush is set to true, all commands will be rejected instead of ignored after using `.end`. +If flush is set to true, all still running commands will be rejected instead of ignored after using `.end`. This example closes the connection to the Redis server before the replies have been read. You probably don't want to do this: @@ -263,8 +263,7 @@ client.get("foo_rand000000000000", function (err, reply) { }); ``` -`client.end()` is useful for timeout cases where something is stuck or taking too long and you want -to start over. +`client.end()` without the flush parameter should not be used in production! ## client.unref() diff --git a/test/auth.spec.js b/test/auth.spec.js index 35481230ae..1e79f023e1 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -24,7 +24,9 @@ describe("client authentication", function () { client = null; }); afterEach(function () { - client.end(); + // Explicitly ignore still running commands + // The ready command could still be running + client.end(false); }); it("allows auth to be provided with 'auth' method", function (done) { diff --git a/test/commands/blpop.spec.js b/test/commands/blpop.spec.js index e8042d6053..fc022a9185 100644 --- a/test/commands/blpop.spec.js +++ b/test/commands/blpop.spec.js @@ -61,8 +61,8 @@ describe("The 'blpop' method", function () { }); afterEach(function () { - client.end(); - bclient.end(); + client.end(true); + bclient.end(true); }); }); }); diff --git a/test/commands/client.spec.js b/test/commands/client.spec.js index 9014af862a..49497b9973 100644 --- a/test/commands/client.spec.js +++ b/test/commands/client.spec.js @@ -28,8 +28,8 @@ describe("The 'client' method", function () { }); afterEach(function () { - client.end(); - client2.end(); + client.end(true); + client2.end(true); }); describe('list', function () { diff --git a/test/commands/dbsize.spec.js b/test/commands/dbsize.spec.js index 6e362087a5..aa1fb57fcf 100644 --- a/test/commands/dbsize.spec.js +++ b/test/commands/dbsize.spec.js @@ -53,7 +53,7 @@ describe("The 'dbsize' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); it("returns a zero db size", function (done) { diff --git a/test/commands/del.spec.js b/test/commands/del.spec.js index 5502e91b6c..d5dc8fbb64 100644 --- a/test/commands/del.spec.js +++ b/test/commands/del.spec.js @@ -50,7 +50,7 @@ describe("The 'del' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/eval.spec.js b/test/commands/eval.spec.js index bdb0d48061..53cff94e71 100644 --- a/test/commands/eval.spec.js +++ b/test/commands/eval.spec.js @@ -22,7 +22,7 @@ describe("The 'eval' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); it('converts a float to an integer when evaluated', function (done) { diff --git a/test/commands/exits.spec.js b/test/commands/exits.spec.js index 030e68c7f5..8d5ac41a31 100644 --- a/test/commands/exits.spec.js +++ b/test/commands/exits.spec.js @@ -33,7 +33,7 @@ describe("The 'exits' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/expire.spec.js b/test/commands/expire.spec.js index a77a32b2f2..99da8e007b 100644 --- a/test/commands/expire.spec.js +++ b/test/commands/expire.spec.js @@ -35,7 +35,7 @@ describe("The 'expire' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/flushdb.spec.js b/test/commands/flushdb.spec.js index f80e5475be..e1c073c0f2 100644 --- a/test/commands/flushdb.spec.js +++ b/test/commands/flushdb.spec.js @@ -50,7 +50,7 @@ describe("The 'flushdb' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); describe("when there is data in Redis", function () { diff --git a/test/commands/geoadd.spec.js b/test/commands/geoadd.spec.js index 690df55de6..70ba278a6b 100644 --- a/test/commands/geoadd.spec.js +++ b/test/commands/geoadd.spec.js @@ -28,7 +28,7 @@ describe("The 'geoadd' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/get.spec.js b/test/commands/get.spec.js index cfefe46351..f51201b990 100644 --- a/test/commands/get.spec.js +++ b/test/commands/get.spec.js @@ -56,7 +56,7 @@ describe("The 'get' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); describe("when the key exists in Redis", function () { diff --git a/test/commands/getset.spec.js b/test/commands/getset.spec.js index 289257573a..11465bf495 100644 --- a/test/commands/getset.spec.js +++ b/test/commands/getset.spec.js @@ -52,7 +52,7 @@ describe("The 'getset' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); describe("when the key exists in Redis", function () { diff --git a/test/commands/hgetall.spec.js b/test/commands/hgetall.spec.js index 2a734052b5..4e219326f2 100644 --- a/test/commands/hgetall.spec.js +++ b/test/commands/hgetall.spec.js @@ -77,7 +77,7 @@ describe("The 'hgetall' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/hincrby.spec.js b/test/commands/hincrby.spec.js index cfa1f13297..d2d03c9546 100644 --- a/test/commands/hincrby.spec.js +++ b/test/commands/hincrby.spec.js @@ -33,7 +33,7 @@ describe("The 'hincrby' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/hlen.spec.js b/test/commands/hlen.spec.js index d5d6b14992..e366582b91 100644 --- a/test/commands/hlen.spec.js +++ b/test/commands/hlen.spec.js @@ -31,7 +31,7 @@ describe("The 'hlen' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/hmget.spec.js b/test/commands/hmget.spec.js index a6f566ec69..4e90dd40a0 100644 --- a/test/commands/hmget.spec.js +++ b/test/commands/hmget.spec.js @@ -64,7 +64,7 @@ describe("The 'hmget' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/hmset.spec.js b/test/commands/hmset.spec.js index 1f8f15096d..2dbc62e7fc 100644 --- a/test/commands/hmset.spec.js +++ b/test/commands/hmset.spec.js @@ -110,7 +110,7 @@ describe("The 'hmset' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/hset.spec.js b/test/commands/hset.spec.js index 8ce8996d86..c08150382e 100644 --- a/test/commands/hset.spec.js +++ b/test/commands/hset.spec.js @@ -56,7 +56,7 @@ describe("The 'hset' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/incr.spec.js b/test/commands/incr.spec.js index 3803585ff4..2f7daae0d1 100644 --- a/test/commands/incr.spec.js +++ b/test/commands/incr.spec.js @@ -29,7 +29,7 @@ describe("The 'incr' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); it("reports an error", function (done) { @@ -64,7 +64,7 @@ describe("The 'incr' method", function () { }); after(function () { - client.end(); + client.end(true); }); it("changes the last digit from 2 to 3", function (done) { diff --git a/test/commands/keys.spec.js b/test/commands/keys.spec.js index 5cb8422805..2c977f664d 100644 --- a/test/commands/keys.spec.js +++ b/test/commands/keys.spec.js @@ -63,7 +63,7 @@ describe("The 'keys' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/mget.spec.js b/test/commands/mget.spec.js index 447fac0490..0907558e56 100644 --- a/test/commands/mget.spec.js +++ b/test/commands/mget.spec.js @@ -63,7 +63,7 @@ describe("The 'mget' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/mset.spec.js b/test/commands/mset.spec.js index 366f52c889..c61c3d726c 100644 --- a/test/commands/mset.spec.js +++ b/test/commands/mset.spec.js @@ -52,7 +52,7 @@ describe("The 'mset' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); describe("and a callback is specified", function () { diff --git a/test/commands/msetnx.spec.js b/test/commands/msetnx.spec.js index e89780ac75..e3f1d3afaa 100644 --- a/test/commands/msetnx.spec.js +++ b/test/commands/msetnx.spec.js @@ -31,7 +31,7 @@ describe("The 'msetnx' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/randomkey.test.js b/test/commands/randomkey.test.js index 870726daef..72fd2fda88 100644 --- a/test/commands/randomkey.test.js +++ b/test/commands/randomkey.test.js @@ -28,7 +28,7 @@ describe("The 'randomkey' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/rename.spec.js b/test/commands/rename.spec.js index 65dad08e7f..dc1de1e3af 100644 --- a/test/commands/rename.spec.js +++ b/test/commands/rename.spec.js @@ -31,7 +31,7 @@ describe("The 'rename' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/renamenx.spec.js b/test/commands/renamenx.spec.js index e5020155ba..bd4e823235 100644 --- a/test/commands/renamenx.spec.js +++ b/test/commands/renamenx.spec.js @@ -34,7 +34,7 @@ describe("The 'renamenx' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/rpush.spec.js b/test/commands/rpush.spec.js index 2a0d72fd22..b6c1562b80 100644 --- a/test/commands/rpush.spec.js +++ b/test/commands/rpush.spec.js @@ -29,7 +29,7 @@ describe("The 'rpush' command", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sadd.spec.js b/test/commands/sadd.spec.js index 9aa246487d..504dc47541 100644 --- a/test/commands/sadd.spec.js +++ b/test/commands/sadd.spec.js @@ -55,7 +55,7 @@ describe("The 'sadd' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/scard.spec.js b/test/commands/scard.spec.js index 5246782309..8c8eb70d1f 100644 --- a/test/commands/scard.spec.js +++ b/test/commands/scard.spec.js @@ -24,7 +24,7 @@ describe("The 'scard' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/script.spec.js b/test/commands/script.spec.js index c3e1340702..a82ab09d19 100644 --- a/test/commands/script.spec.js +++ b/test/commands/script.spec.js @@ -23,7 +23,7 @@ describe("The 'script' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); it("loads script with client.script('load')", function (done) { diff --git a/test/commands/sdiff.spec.js b/test/commands/sdiff.spec.js index 435ddf63e9..7121b1e95f 100644 --- a/test/commands/sdiff.spec.js +++ b/test/commands/sdiff.spec.js @@ -40,7 +40,7 @@ describe("The 'sdiff' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sdiffstore.spec.js b/test/commands/sdiffstore.spec.js index 00bc2c8e12..1963317a70 100644 --- a/test/commands/sdiffstore.spec.js +++ b/test/commands/sdiffstore.spec.js @@ -40,7 +40,7 @@ describe("The 'sdiffstore' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/select.spec.js b/test/commands/select.spec.js index 3a90703332..bf41fc46a0 100644 --- a/test/commands/select.spec.js +++ b/test/commands/select.spec.js @@ -41,7 +41,7 @@ describe("The 'select' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); it("changes the database and calls the callback", function (done) { diff --git a/test/commands/set.spec.js b/test/commands/set.spec.js index e76b0c88db..7a508920a1 100644 --- a/test/commands/set.spec.js +++ b/test/commands/set.spec.js @@ -50,7 +50,7 @@ describe("The 'set' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); describe("and a callback is specified", function () { diff --git a/test/commands/setex.spec.js b/test/commands/setex.spec.js index 7d0b152ae0..47f616253e 100644 --- a/test/commands/setex.spec.js +++ b/test/commands/setex.spec.js @@ -34,7 +34,7 @@ describe("The 'setex' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/setnx.spec.js b/test/commands/setnx.spec.js index 229eb2b58b..d72c36696e 100644 --- a/test/commands/setnx.spec.js +++ b/test/commands/setnx.spec.js @@ -30,7 +30,7 @@ describe("The 'setnx' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sinter.spec.js b/test/commands/sinter.spec.js index a655b86068..8e547923db 100644 --- a/test/commands/sinter.spec.js +++ b/test/commands/sinter.spec.js @@ -56,7 +56,7 @@ describe("The 'sinter' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sinterstore.spec.js b/test/commands/sinterstore.spec.js index 38b7dcfb5b..d4a0c228a4 100644 --- a/test/commands/sinterstore.spec.js +++ b/test/commands/sinterstore.spec.js @@ -41,7 +41,7 @@ describe("The 'sinterstore' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sismember.spec.js b/test/commands/sismember.spec.js index eefd37e408..8f556e741f 100644 --- a/test/commands/sismember.spec.js +++ b/test/commands/sismember.spec.js @@ -28,7 +28,7 @@ describe("The 'sismember' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/slowlog.spec.js b/test/commands/slowlog.spec.js index b2fbebdfe9..b297a985f7 100644 --- a/test/commands/slowlog.spec.js +++ b/test/commands/slowlog.spec.js @@ -34,7 +34,7 @@ describe("The 'slowlog' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/smembers.spec.js b/test/commands/smembers.spec.js index e92a658d50..c19efc2c81 100644 --- a/test/commands/smembers.spec.js +++ b/test/commands/smembers.spec.js @@ -31,7 +31,7 @@ describe("The 'smembers' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/smove.spec.js b/test/commands/smove.spec.js index 123ff163a7..436069be6a 100644 --- a/test/commands/smove.spec.js +++ b/test/commands/smove.spec.js @@ -33,7 +33,7 @@ describe("The 'smove' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sort.spec.js b/test/commands/sort.spec.js index 97e64a686b..28355d9fe8 100644 --- a/test/commands/sort.spec.js +++ b/test/commands/sort.spec.js @@ -122,7 +122,7 @@ describe("The 'sort' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/spop.spec.js b/test/commands/spop.spec.js index f8d4d46ede..b44d9b172b 100644 --- a/test/commands/spop.spec.js +++ b/test/commands/spop.spec.js @@ -31,7 +31,7 @@ describe("The 'spop' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/srem.spec.js b/test/commands/srem.spec.js index e4e552ec5d..dc79134d63 100644 --- a/test/commands/srem.spec.js +++ b/test/commands/srem.spec.js @@ -62,7 +62,7 @@ describe("The 'srem' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sunion.spec.js b/test/commands/sunion.spec.js index 638cb116a6..deb751b1af 100644 --- a/test/commands/sunion.spec.js +++ b/test/commands/sunion.spec.js @@ -39,7 +39,7 @@ describe("The 'sunion' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sunionstore.spec.js b/test/commands/sunionstore.spec.js index 3ebb10b085..54cdddf52e 100644 --- a/test/commands/sunionstore.spec.js +++ b/test/commands/sunionstore.spec.js @@ -42,7 +42,7 @@ describe("The 'sunionstore' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/sync.spec.js b/test/commands/sync.spec.js index 6a9813112b..bd793a0d38 100644 --- a/test/commands/sync.spec.js +++ b/test/commands/sync.spec.js @@ -37,7 +37,7 @@ describe.skip("The 'sync' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/ttl.spec.js b/test/commands/ttl.spec.js index deec21720a..1df47cfe31 100644 --- a/test/commands/ttl.spec.js +++ b/test/commands/ttl.spec.js @@ -31,7 +31,7 @@ describe("The 'ttl' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/type.spec.js b/test/commands/type.spec.js index c652e76d96..5e592054d0 100644 --- a/test/commands/type.spec.js +++ b/test/commands/type.spec.js @@ -48,7 +48,7 @@ describe("The 'type' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/watch.spec.js b/test/commands/watch.spec.js index 87bcc81d22..3cc28334f8 100644 --- a/test/commands/watch.spec.js +++ b/test/commands/watch.spec.js @@ -22,7 +22,7 @@ describe("The 'watch' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); it('does not execute transaction if watched key was modified prior to execution', function (done) { diff --git a/test/commands/zadd.spec.js b/test/commands/zadd.spec.js index 514c51b339..9536b2688a 100644 --- a/test/commands/zadd.spec.js +++ b/test/commands/zadd.spec.js @@ -40,7 +40,7 @@ describe("The 'zadd' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/zscan.spec.js b/test/commands/zscan.spec.js index f655bdeac0..0794b8941a 100644 --- a/test/commands/zscan.spec.js +++ b/test/commands/zscan.spec.js @@ -42,7 +42,7 @@ describe("The 'zscan' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/commands/zscore.spec.js b/test/commands/zscore.spec.js index 43964a32b3..6bfd279668 100644 --- a/test/commands/zscore.spec.js +++ b/test/commands/zscore.spec.js @@ -28,7 +28,7 @@ describe("The 'zscore' method", function () { }); afterEach(function () { - client.end(); + client.end(true); }); }); }); diff --git a/test/connection.spec.js b/test/connection.spec.js index 8383e79454..2223ba70e8 100644 --- a/test/connection.spec.js +++ b/test/connection.spec.js @@ -16,7 +16,7 @@ describe("connection tests", function () { client = null; }); afterEach(function () { - client.end(); + client.end(true); }); describe("on lost connection", function () { @@ -174,7 +174,7 @@ describe("connection tests", function () { client.on('connect', function () { assert.strictEqual(client.stream._idleTimeout, -1); assert.strictEqual(client.stream._events.timeout, undefined); - done(); + client.on('ready', done); }); }); diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 4650a0a333..2c03de5de9 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -32,7 +32,8 @@ describe("The node_redis client", function () { var client; afterEach(function () { - client.end(); + // Explicitly ignore still running commands + client.end(true); }); describe("when connected", function () { @@ -97,11 +98,14 @@ describe("The node_redis client", function () { describe(".end", function () { it('used without flush', function(done) { + var finished = false; var end = helper.callFuncAfter(function() { - done(new Error('failed')); + if (!finished) { + done(new Error('failed')); + } }, 20); var cb = function(err, res) { - assert.equal(err.message, "SET can't be processed. The connection has already been closed."); + assert(/The connection has already been closed/.test(err.message)); end(); }; for (var i = 0; i < 20; i++) { @@ -110,7 +114,10 @@ describe("The node_redis client", function () { } client.set('foo', 'bar', cb); } - setTimeout(done, 250); + setTimeout(function () { + finished = true; + done(); + }, 250); }); it('used with flush set to true', function(done) { @@ -255,14 +262,7 @@ describe("The node_redis client", function () { describe('domain', function () { it('allows client to be executed from within domain', function (done) { - var domain; - - try { - domain = require('domain').create(); - } catch (err) { - console.log("Skipping test because this version of node doesn't have domains."); - return done(); - } + var domain = require('domain').create(); domain.run(function () { client.set('domain', 'value', function (err, res) { @@ -505,19 +505,24 @@ describe("The node_redis client", function () { max_attempts: 0, parser: parser }); - + var finished = false; client.on('error', function(e) { // ignore, b/c expecting a "can't connect" error }); return setTimeout(function() { client.set('foo', 'bar', function(err, result) { - // This should never be called - return done(err); + if (!finished) { + // This should never be called + return done(err); + } else { + assert.strictEqual(err.message, "The command can't be processed. The connection has already been closed."); + } }); return setTimeout(function() { assert.strictEqual(client.offline_queue.length, 1); + finished = true; return done(); }, 25); }, 50);