1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Stricten tests by always ending redis with .end(true) if possible

This commit is contained in:
Ruben Bridgewater
2015-11-22 16:56:54 +01:00
parent 0913a4d521
commit 8bf794fb36
57 changed files with 83 additions and 77 deletions

View File

@@ -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()

View File

@@ -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) {

View File

@@ -61,8 +61,8 @@ describe("The 'blpop' method", function () {
});
afterEach(function () {
client.end();
bclient.end();
client.end(true);
bclient.end(true);
});
});
});

View File

@@ -28,8 +28,8 @@ describe("The 'client' method", function () {
});
afterEach(function () {
client.end();
client2.end();
client.end(true);
client2.end(true);
});
describe('list', function () {

View File

@@ -53,7 +53,7 @@ describe("The 'dbsize' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
it("returns a zero db size", function (done) {

View File

@@ -50,7 +50,7 @@ describe("The 'del' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -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) {

View File

@@ -33,7 +33,7 @@ describe("The 'exits' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -35,7 +35,7 @@ describe("The 'expire' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -50,7 +50,7 @@ describe("The 'flushdb' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
describe("when there is data in Redis", function () {

View File

@@ -28,7 +28,7 @@ describe("The 'geoadd' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -56,7 +56,7 @@ describe("The 'get' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
describe("when the key exists in Redis", function () {

View File

@@ -52,7 +52,7 @@ describe("The 'getset' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
describe("when the key exists in Redis", function () {

View File

@@ -77,7 +77,7 @@ describe("The 'hgetall' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -33,7 +33,7 @@ describe("The 'hincrby' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -31,7 +31,7 @@ describe("The 'hlen' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -64,7 +64,7 @@ describe("The 'hmget' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -110,7 +110,7 @@ describe("The 'hmset' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -56,7 +56,7 @@ describe("The 'hset' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -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) {

View File

@@ -63,7 +63,7 @@ describe("The 'keys' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -63,7 +63,7 @@ describe("The 'mget' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -52,7 +52,7 @@ describe("The 'mset' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
describe("and a callback is specified", function () {

View File

@@ -31,7 +31,7 @@ describe("The 'msetnx' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -28,7 +28,7 @@ describe("The 'randomkey' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -31,7 +31,7 @@ describe("The 'rename' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -34,7 +34,7 @@ describe("The 'renamenx' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -29,7 +29,7 @@ describe("The 'rpush' command", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -55,7 +55,7 @@ describe("The 'sadd' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -24,7 +24,7 @@ describe("The 'scard' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -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) {

View File

@@ -40,7 +40,7 @@ describe("The 'sdiff' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -40,7 +40,7 @@ describe("The 'sdiffstore' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -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) {

View File

@@ -50,7 +50,7 @@ describe("The 'set' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
describe("and a callback is specified", function () {

View File

@@ -34,7 +34,7 @@ describe("The 'setex' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -30,7 +30,7 @@ describe("The 'setnx' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -56,7 +56,7 @@ describe("The 'sinter' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -41,7 +41,7 @@ describe("The 'sinterstore' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -28,7 +28,7 @@ describe("The 'sismember' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -34,7 +34,7 @@ describe("The 'slowlog' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -31,7 +31,7 @@ describe("The 'smembers' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -33,7 +33,7 @@ describe("The 'smove' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -122,7 +122,7 @@ describe("The 'sort' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -31,7 +31,7 @@ describe("The 'spop' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -62,7 +62,7 @@ describe("The 'srem' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -39,7 +39,7 @@ describe("The 'sunion' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -42,7 +42,7 @@ describe("The 'sunionstore' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -37,7 +37,7 @@ describe.skip("The 'sync' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -31,7 +31,7 @@ describe("The 'ttl' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -48,7 +48,7 @@ describe("The 'type' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -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) {

View File

@@ -40,7 +40,7 @@ describe("The 'zadd' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -42,7 +42,7 @@ describe("The 'zscan' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -28,7 +28,7 @@ describe("The 'zscore' method", function () {
});
afterEach(function () {
client.end();
client.end(true);
});
});
});

View File

@@ -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);
});
});

View File

@@ -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);